/** * Upload resources associated to an internal component on a specified * external component * * @param x the internal component with upload commands * @param owner the external component on which the resources are about to * be uploaded * @param jc the connector used to upload */ private void executeUploadCommands(InternalComponentInstance x, VMInstance owner, Connector jc) { journal.log(Level.INFO, ">> Upload "+x.getType().getName()); unlessNotNull("Cannot upload with an argument at null", x, owner, jc); for (Resource r : x.getType().getResources()) { for (String path : r.getUploadCommand().keySet()) { jc.uploadFile(path, r.getUploadCommand().get(path), owner.getId(), "ubuntu", owner.getType().getPrivateKey()); } } }
protected void restartHostedComponents(VMInstance ci){ journal.log(Level.INFO, ">> Restarting Hosted components of: "+ci.getName()); for(InternalComponentInstance ici: allHostedComponents(ci)){ Provider p=ci.getType().getProvider(); Connector c2=ConnectorFactory.createIaaSConnector(p); for(Resource r: ici.getType().getResources()){ dep.start(c2,ci.getType(),ci,r.getStartCommand()); } c2.closeConnection(); } }
/** * Stop a specific component instance * * @param a An InternalComponent Instance * @throws MalformedURLException */ private void stopInternalComponent(InternalComponentInstance a) { VMInstance ownerVM = (VMInstance) findDestinationWhenNoRequiredExecutionPlatformSpecified(a); //TODO: to be generalized if (ownerVM != null) { VM n = ownerVM.getType(); Connector jc = ConnectorFactory.createIaaSConnector(n.getProvider()); for (Resource r : a.getType().getResources()) { String stopCommand = r.getStopCommand(); //jc.execCommand(ownerVM.getId(), stopCommand, "ubuntu", n.getPrivateKey()); executeCommand(ownerVM, jc, stopCommand); } jc.closeConnection(); coordinator.updateStatusInternalComponent(a.getName(), State.UNINSTALLED.toString(), CloudAppDeployer.class.getName()); //a.setStatus(State.CONFIGURED); } }
/** * For each component, execute the puppet manifest associated * @param components */ private void configureWithPuppet(ComponentInstanceGroup<InternalComponentInstance> components){ unlessNotNull("Cannot configure null!", components); Connector jc; for (InternalComponentInstance ic : components) { if(ic.externalHost().isVM()){ for(Resource r: ic.getType().getResources()){ if(r instanceof PuppetResource){ PuppetResource pr=(PuppetResource)r; if(!pr.getConfigurationFile().isEmpty()){ journal.log(Level.INFO, ">> Using Puppet to configure the following component: "+ic.getName()); VMInstance n= ic.getHost().asExternal().asVM(); Provider p = n.getType().getProvider(); managePuppet(pr,n, pr.getName(),pr.getConfigurationFile()); } } } } } }
for (Resource r : x.getType().getResources()) { String configurationCommand = CloudMLQueryUtil.cloudmlStringRecover(r.getConfigureCommand(), r, x); configure(jc, n, ownerVM, configurationCommand, r.getRequireCredentials()); for (Resource r : x.getType().getResources()) { String startCommand = CloudMLQueryUtil.cloudmlStringRecover(r.getStartCommand(), r, x); start(jc, n, ownerVM, startCommand);
public void run() { VMInstance vmi = deploy.getComponentInstances().onlyVMs().withID(id); if (vmi != null) { Provider provider = vmi.getType().getProvider(); Connector c = ConnectorFactory.createIaaSConnector(provider); for(InternalComponentInstance ici : vmi.hostedComponents()){ InternalComponent ic=ici.getType(); for(Resource r : ic.getResources()){ c.execCommand(vmi.getId(),r.getStopCommand(),"ubuntu",vmi.getType().getPrivateKey()); } } c.stopVM(vmi); coordinator.updateStatus(vmi.getName(), ComponentInstance.State.STOPPED, Facade.class.getName()); c.closeConnection(); } } });
private void executeInstallCommand(InternalComponentInstance x, VMInstance owner, Connector jc) { unlessNotNull("Cannot install with an argument at null", x, owner, jc); for (Resource r : x.getType().getResources()) { if (!r.getInstallCommand().equals("")) { if (r.getRequireCredentials()) { jc.execCommand(owner.getId(), CloudMLQueryUtil.cloudmlStringRecover(r.getInstallCommand(), r, x) + " " + owner.getType().getProvider().getCredentials().getLogin() + " " + owner.getType().getProvider().getCredentials().getPassword(), "ubuntu", owner.getType().getPrivateKey()); } else { executeCommand(owner, jc, CloudMLQueryUtil.cloudmlStringRecover(r.getInstallCommand(), r, x)); } } } }
public void run() { VMInstance vmi = deploy.getComponentInstances().onlyVMs().withID(id); if (vmi != null) { Provider provider = vmi.getType().getProvider(); Connector c = ConnectorFactory.createIaaSConnector(provider); c.startVM(vmi); coordinator.updateStatus(vmi.getName(), ComponentInstance.State.RUNNING, Facade.class.getName()); for(InternalComponentInstance ici : vmi.hostedComponents()){ InternalComponent ic=ici.getType(); for(Resource r : ic.getResources()){ c.execCommand(vmi.getId(),r.getStartCommand(),"ubuntu",vmi.getType().getPrivateKey()); } } c.closeConnection(); } }}); ts.get(i).start();
/** * Retrieve the resources associated to an InternalComponent * * @param x the internalComponent we want to retrieve the resource * @param owner the externalComponent on which the resources will be * downloaded * @param jc the connector used to trigger the commands */ private void executeRetrieveCommand(InternalComponentInstance x, VMInstance owner, Connector jc) { unlessNotNull("Cannot retrieve resources of null!", x, owner, jc); for (Resource r : x.getType().getResources()) { if (!r.getRetrieveCommand().equals("")) { if (r.getRequireCredentials()) jc.execCommand(owner.getId(), CloudMLQueryUtil.cloudmlStringRecover(r.getRetrieveCommand(), r, x) + " " + owner.getType().getProvider().getCredentials().getLogin() + "" + owner.getType().getProvider().getCredentials().getPassword(), "ubuntu", owner.getType().getPrivateKey()); else executeCommand(owner, jc, CloudMLQueryUtil.cloudmlStringRecover(r.getRetrieveCommand(), r, x)); } } }