1 2 package SOFA.SOFAnode.Run; 3 4 import org.omg.CosNaming.NameComponent ; 5 6 import SOFA.SOFAnode.Run.DeplDockRegistry.DeplDockRegistry; 7 import SOFA.SOFAnode.Run.DeplDockRegistry.DeplDockRegistryHelper; 8 import SOFA.SOFAnode.Run.DeplDockRegistry.NotFoundException; 9 import SOFA.SOFAnode.Run.Deployment.DeplDock; 10 11 12 13 17 public class UpdateTool { 18 19 21 public static void main(String [] argv) { 22 if (argv.length != 1) { 23 System.out.println("Bad number of arguments."); 24 System.out.println("Specify name of the deployment dock"); 25 System.exit(1); 26 } 27 28 if (System.getSecurityManager() == null) { 29 System.setSecurityManager(new java.rmi.RMISecurityManager ()); 30 } 31 32 SOFA.Util.CORBAAccess ca = new SOFA.Util.CORBAAccess(); 33 34 NameComponent nc = new NameComponent ("DeplDockRegistry", ""); 35 NameComponent path[] = {nc}; 36 DeplDockRegistry ddr = null; 37 try { 38 System.out.print("Obtaining depldock registry..."); 39 ddr = DeplDockRegistryHelper.narrow(SOFA.Util.CORBAAccess.ncRef.resolve(path)); 40 System.out.println("OK"); 41 } catch (Exception e) { 42 System.out.println("Can't get DeplDock registry."); 43 e.printStackTrace(); 44 System.exit(1); 45 } 46 47 48 byte[] serRef = null; 49 try { 50 System.out.print("Obtaining reference to depldock..."); 51 serRef = ddr.lookup(argv[0]); 52 System.out.println("OK"); 53 } catch (NotFoundException e) { 54 System.out.println("No deployment dock with name \""+argv[1]+"\"."); 55 System.exit(1); 56 } 57 58 SOFA.Connector.Reference ddRef = SOFA.SOFAnode.Run.Deployment.DeplDockImpl.bytesToSofaReference(serRef); 59 60 DeplDock ddock = null; 61 try { 62 System.out.print("Creating connector to depldock..."); 63 ddock = (DeplDock) SOFA.Connector.Boot.DeplDockConnector.createClt(ddRef); 64 System.out.println("OK"); 65 } catch (SOFA.Connector.ConnectorException e) { 66 System.out.println("Can't create connector to deployment dock."); 67 System.exit(1); 68 } 69 70 String [] names = ddock.namesOfAllRunningComponents(); 71 SOFA.Connector.Reference[] refs = new SOFA.Connector.Reference [ names.length ]; 72 for (int i=0; i<names.length; i++) { 73 try { 74 refs[i] = ddock.getReference(names[i]); 75 } catch (SOFA.SOFAnode.Run.Deployment.DeploymentException e) { 76 System.out.println("DeploymentException: "+e.getMessage()); 77 e.printStackTrace(); 78 System.exit(1); 79 } 80 } 81 82 SOFA.Component.DCUP.DCUPComponentManager[] aplcms = new SOFA.Component.DCUP.DCUPComponentManager[refs.length]; 83 for (int i=0; i<refs.length; i++) { 84 try { 85 aplcms[i] = (SOFA.Component.DCUP.DCUPComponentManager) SOFA.Connector.Boot.DCUPComponentManagerConnector.createClt(refs[i]); 86 } catch (SOFA.Connector.ConnectorException e) { 87 System.out.println("ConnectorException: "+e.getMessage()); 88 e.printStackTrace(); 89 System.exit(1); 90 } 91 } 92 93 java.util.ArrayList updatableAplcms = new java.util.ArrayList (); 94 java.util.ArrayList updatableNames = new java.util.ArrayList (); 95 for (int i=0; i<aplcms.length; i++) { 96 if (aplcms[i].isUpdatable()) { 97 updatableAplcms.add(aplcms[i]); 98 updatableNames.add(names[i]); 99 } 100 } 101 102 if (updatableAplcms.size() == 0) { 103 System.out.println("No updatable components in this depldock."); 104 System.exit(0); 105 } 106 107 System.out.println("Choose component for update"); 108 System.out.println("==========================="); 109 for (int i=0;i<updatableNames.size(); i++) { 110 System.out.print(i); 111 System.out.print(" ... "); 112 System.out.println(updatableNames.get(i)+" ("+((SOFA.Component.DCUP.DCUPComponentManager)updatableAplcms.get(i)).getFullName()+")"); 113 } 114 System.out.print(updatableNames.size()); 115 System.out.println(" ... do nothing"); 116 int numOK = 0; 117 try { 118 java.io.BufferedReader in = new java.io.BufferedReader (new java.io.InputStreamReader (System.in)); 119 String ln = in.readLine(); 120 ln.trim(); 121 int num = Integer.parseInt(ln); 122 if (num<0 || num>=(updatableNames.size()+1)) { 123 System.out.println("Bad number"); 124 System.exit(1); 125 } 126 if (num == updatableNames.size()) 127 System.exit(0); 128 numOK = num; 129 } catch (Exception e) { 130 System.out.println("Exception: "+e.getMessage()); 131 e.printStackTrace(); 132 System.exit(1); 133 } 134 135 SOFA.Component.DCUP.DCUPComponentManager dcm = (SOFA.Component.DCUP.DCUPComponentManager) updatableAplcms.get(numOK); 136 String fullName = dcm.getFullName(); 137 String version = getVersionFromFullName(fullName); 138 String name = getNameFromFullName(fullName); 139 140 String trString = System.getProperty("sofa.tr.url","file:/sofa/tr/"); 141 String trPath = trString+"/impl/"; 142 java.util.Properties props = new java.util.Properties (); 143 try { 144 java.net.URL url = new java.net.URL (trPath+"/info"); 145 java.io.InputStream uis = url.openStream(); 146 props.load(uis); 147 uis.close(); 148 } catch (java.net.MalformedURLException e) { 149 System.out.println("MalformedURLException: "+e.getMessage()); 150 e.printStackTrace(); 151 System.exit(1); 152 } catch (java.io.IOException e) { 153 System.out.println("IOException: "+e.getMessage()); 154 System.exit(1); 155 } 156 157 if (props.size() == 1) { 158 System.out.println("No other versions of the component for update"); 159 System.exit(0); 160 } 161 162 String [] vers = new String [props.size()-1]; 163 int i = 0; 164 System.out.println("Choose new component to update"); 165 System.out.println("=============================="); 166 for (java.util.Enumeration e = props.keys(); e.hasMoreElements(); ) { 167 String v = (String ) e.nextElement(); 168 if (v.compareTo(fullName) != 0) { 169 System.out.print(i); 170 System.out.print(" ... "); 171 System.out.println(v); 172 vers[i++] = v; 173 } 174 } 175 System.out.print(i); 176 System.out.println(" ... do nothing"); 177 numOK = 0; 178 try { 179 java.io.BufferedReader in = new java.io.BufferedReader (new java.io.InputStreamReader (System.in)); 180 String ln = in.readLine(); 181 ln.trim(); 182 int num = Integer.parseInt(ln); 183 if (num<0 || num>=(vers.length+1)) { 184 System.out.println("Bad number"); 185 System.exit(1); 186 } 187 if (num == vers.length) 188 System.exit(0); 189 numOK = num; 190 } catch (Exception e) { 191 System.out.println("Exception: "+e.getMessage()); 192 e.printStackTrace(); 193 System.exit(1); 194 } 195 196 System.out.print("Obtaining and parsing new deployment descriptor..."); 197 SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor depldesc = TRLauncher.getDeplDescr(vers[numOK], "index.dc"); 198 System.out.println("OK"); 199 200 System.out.print("Updating component..."); 201 try { 202 dcm.updateComponent(depldesc, new SOFA.SOFAnode.Run.StorageImpl()); 203 } catch (SOFA.Component.ComponentLifecycleException e) { 204 System.out.println("ComponentLifecycleException: "+e.getMessage()); 205 e.printStackTrace(); 206 System.exit(1); 207 } 208 System.out.println("OK"); 209 210 } 211 212 213 private static String getVersionFromFullName(String name) { 214 return name.substring(name.indexOf('[')+1, name.indexOf(']')); 215 } 216 217 private static String getNameFromFullName(String name) { 218 return name.substring(0, name.indexOf('[')); 219 } 220 221 private static String nameToFileName(String name) { 222 return name.replaceAll("::", "/"); 223 } 224 225 226 } 227 | Popular Tags |