/** * Retrieve the external component on which an component should be deployed * * @param component the component who want to retrieve the destination * @return */ public ExternalComponentInstance getDestination(ComponentInstance component) { unlessNotNull("Cannot find destination of null!", component); if (component instanceof InternalComponentInstance) { InternalComponentInstance internalComponent = (InternalComponentInstance) component; return internalComponent.externalHost(); } else { return (ExternalComponentInstance) component; } }
@Override public boolean equals(Object other) { if (other instanceof InternalComponentInstance) { InternalComponentInstance otherCompInst = (InternalComponentInstance) other; Boolean match = getName().equals(otherCompInst.getName()); match &= getType().equals(otherCompInst.getType()); if (externalHost() != null) { match &= externalHost().equals(otherCompInst.externalHost()); }else{ match &= (otherCompInst.externalHost() == null); } if (requiredExecutionPlatformInstance != null) { return match && requiredExecutionPlatformInstance.getName().equals(otherCompInst.getRequiredExecutionPlatform().getName()); } else { return match && (otherCompInst.getRequiredExecutionPlatform() == null); } } else { return false; } }
/** * Compares the components between the targeted and the current deployment * model */ public void compareComponents() { journal.log(Level.INFO, ">> Comparing Internal Components ..."); Boolean match = false; for (InternalComponentInstance ni : currentDM.getComponentInstances().onlyInternals()) { secondloop: { for (InternalComponentInstance ni2 : targetDM.getComponentInstances().onlyInternals()) { match = ni.equals(ni2); if (ni.equals(ni2) && ni.externalHost().equals(ni2.externalHost())) { matchingComponents.put(ni, ni2); break secondloop; } } } if (!match) { removedComponents.add(ni); } } //add the rest addComponents(); }
/** * @return the external component at the bottom of the underlying software * stack. For instance, if an application, is running on the top of a war * container, itself running on linux virtual machine, externalHost will * return the linux VM. */ public ExternalComponentInstance<? extends ExternalComponent> externalHost() { final ComponentInstance<? extends Component> directHost = getHost(); if(directHost != null){ if (directHost.isInternal()) { return directHost.asInternal().externalHost(); } return directHost.asExternal(); }else{ return null; } }
if(p.getValue().startsWith("$")){ if(p.getValue().equals("${this.host.id}")){ value=c.externalHost().asVM().getId(); value=c.externalHost().getName(); value=c.externalHost().getType().getName(); value=c.externalHost().asVM().getType().getProvider().getName(); return setEnvVarCommand(c.externalHost().asVM(), p.getName().split(":")[1], value);
if(p.getValue().startsWith("$")){ if(p.getValue().equals("${this.host.id}")){ value=c.externalHost().asVM().getId(); value=c.externalHost().getName(); value=c.externalHost().getType().getName(); value=c.externalHost().asVM().getType().getProvider().getName(); setEnvVar(c.externalHost().asVM(), p.getName().split(":")[1], value);
private static InternalComponent fromCloudmlToModaMP(InternalComponentInstance toTranslate){ InternalComponent toReturn = new InternalComponent(); String id = toTranslate.getName(); toReturn.setId(id); toReturn.setType(String.valueOf(toTranslate.getType().getName())); toReturn.addRequiredComponent(toTranslate.externalHost().getName()); return toReturn; } //Translate a cloud provider from cloudML to Monitoring Platform QoS-model
protected void startImpactedComponents(Set<ComponentInstance> listOfAllComponentImpacted, Map<InternalComponentInstance, InternalComponentInstance> duplicatedGraph){ for(ComponentInstance ici: listOfAllComponentImpacted){ if(ici.isInternal()){ Provider p=ici.asInternal().externalHost().asVM().getType().getProvider(); Connector c2=ConnectorFactory.createIaaSConnector(p); for(Resource r: ici.getType().getResources()){ dep.start(c2,ci.getType(),ici.asInternal().externalHost().asVM(),r.getStartCommand()); } c2.closeConnection(); } coordinator.updateStatusInternalComponent(ici.getName(), InternalComponentInstance.State.RUNNING.toString(), CloudAppDeployer.class.getName()); } for(InternalComponentInstance ici: duplicatedGraph.values()){ coordinator.updateStatusInternalComponent(ici.getName(), InternalComponentInstance.State.RUNNING.toString(), CloudAppDeployer.class.getName()); } }
protected void configureImpactedComponents(Set<ComponentInstance> listOfAllComponentImpacted, Map<InternalComponentInstance, InternalComponentInstance> duplicatedGraph){ for(ComponentInstance ici: listOfAllComponentImpacted){ coordinator.updateStatusInternalComponent(ici.getName(), InternalComponentInstance.State.INSTALLED.toString(), CloudAppDeployer.class.getName()); if(ici.isInternal()){ Provider p=ici.asInternal().externalHost().asVM().getType().getProvider(); Connector c2=ConnectorFactory.createIaaSConnector(p); for(Resource r: ici.getType().getResources()){ dep.configure(c2, ci.getType(), ici.asInternal().externalHost().asVM(), r.getConfigureCommand(),false); } c2.closeConnection(); } coordinator.updateStatusInternalComponent(ici.getName(), InternalComponentInstance.State.CONFIGURED.toString(), CloudAppDeployer.class.getName()); } }
private Boolean isPaaS2PaaS(RelationshipInstance bi){ if(bi.getRequiredEnd().getOwner().get().isInternal()){ if(bi.getProvidedEnd().getOwner().get().isInternal()){ if(!bi.getRequiredEnd().getOwner().get().asInternal().externalHost().isVM() && !bi.getProvidedEnd().getOwner().get().asInternal().externalHost().isVM()){ return true; } } } return false; }
/** * 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()); } } } } } }
private void startExecutes(InternalComponentInstance x){ VMInstance ownerVM = x.externalHost().asVM(); //need some tests but if you need to build PaaS then it means that you want to deploy on IaaS VM n = ownerVM.getType(); Connector jc = ConnectorFactory.createIaaSConnector(n.getProvider()); ComponentInstance host = x.getHost(); if (!alreadyStarted.contains(host)) { if (host.isInternal()) { startExecutes(host.asInternal()); for (Resource r : host.getType().getResources()) { String startCommand = CloudMLQueryUtil.cloudmlStringRecover(r.getStartCommand(), r, x); start(jc, n, ownerVM, startCommand); } coordinator.updateStatusInternalComponent(host.getName(), State.RUNNING.toString(), CloudAppDeployer.class.getName()); alreadyStarted.add(host); } } jc.closeConnection(); }
for (InternalComponentInstance x : components) { if (!alreadyStarted.contains(x)) { ExternalComponentInstance owner = x.externalHost(); if (owner instanceof VMInstance) { //TODO: refactor and be more generic for external component in general VMInstance ownerVM = (VMInstance) owner;
private void buildExecutes(InternalComponentInstance x) { VMInstance ownerVM = x.externalHost().asVM(); //need some tests but if you need to build PaaS then it means that you want to deploy on IaaS VM n = ownerVM.getType();
ExternalComponentInstance serveri2 = bi.getProvidedEnd().getOwner().get().asInternal().externalHost(); ExternalComponent pltf = clienti.asInternal().externalHost().getType(); PaaSConnector connector = (PaaSConnector) ConnectorFactory.createPaaSConnector(pltf.getProvider()); connector.setEnvVar(clienti.getName(), s.getName(), serveri2.getPublicAddress());
Connector jc; if (!alreadyDeployed.contains(instance) && (instance.getRequiredExecutionPlatform() != null)) { ExternalComponentInstance host = instance.externalHost(); if (host.isVM()) { VMInstance ownerVM = host.asVM();
VMInstance ownerVM = x.externalHost().asVM(); //need some tests but if you need to build PaaS then it means that you want to deploy on IaaS VM n = ownerVM.getType();