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
@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; } }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("Instance " + getName() + " : " + getType().getName() +" id:"+this.hashCode()); for(PortInstance p : this.getProvidedPorts()) builder.append("-Provided port:"+p.getName()); for(PortInstance p : this.getRequiredPorts()) builder.append("-Required port:"+p.getName()); return builder.toString(); }
unlessNotNull("Cannot deploy null!", instance); Connector jc; if (!alreadyDeployed.contains(instance) && (instance.getRequiredExecutionPlatform() != null)) { ExternalComponentInstance host = instance.externalHost(); if (host.isVM()) { VMInstance ownerVM = host.asVM(); coordinator.updateStatusInternalComponent(instance.getName(), State.INSTALLED.toString(), CloudAppDeployer.class.getName()); int minRam=0; String stack = ""; if(instance.getType().hasProperty("stack")) stack = instance.getType().getProperties().valueOf("stack"); if(instance.hasProperty("stack")) stack = instance.getProperties().valueOf("stack"); if(instance.getType().hasProperty("buildpack")) stack = instance.getType().getProperties().valueOf("buildpack"); if(instance.hasProperty("buildpack")) stack = instance.getProperties().valueOf("buildpack"); if(instance.getType().hasProperty("minRAM")) minRam = Integer.parseInt(instance.getType().getProperties().valueOf("minRAM")); String url=connector.createEnvironmentWithWar( instance.getName(), instance.getName(), host.getName(), stack, minRam, instance.getType().getProperties().valueOf("warfile"), instance.getType().hasProperty("version") ? instance.getType().getProperties().valueOf("version") : "default-cloudml"
public boolean match(InternalComponentInstance component) { return match(component.getType()); }
/** * 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()); } } } } } }
public void internalComponentInstanceToPOJO(net.cloudml.core.InternalComponentInstance kInternalComponentInstance) { checkForNull(kInternalComponentInstance, "Cannot convert null!"); InternalComponentInstance ai = new InternalComponentInstance(kInternalComponentInstance.getName(), internalComponents.get(kInternalComponentInstance.getType().getName())); convertProperties(kInternalComponentInstance, ai); internalComponentInstances.put(ai.getName(), ai); initRequiredExecutionPlatformInstance(kInternalComponentInstance, ai); initProvidedExecutionPlatformInstances(kInternalComponentInstance, ai); //TODO: destination convertAndAddProvidedPortInstances(kInternalComponentInstance.getProvidedPortInstances(), ai); RequiredPortInstanceGroup rpig=new RequiredPortInstanceGroup(); for (net.cloudml.core.RequiredPortInstance kapi: kInternalComponentInstance.getRequiredPortInstances()) { RequiredPortInstance api = new RequiredPortInstance(kapi.getName(), requiredPorts.get(ai.getType().getName() + "_" + kapi.getType().getName())); api.getOwner().set(ai); convertProperties(kapi, api); //ai.getRequiredPorts().add(api); rpig.add(api); requiredPortInstances.put(api.getName(), api); } ai.setRequiredPorts(rpig); model.getComponentInstances().add(ai); }
rib.put(name,aRelationshipInstance() .named(name) .from(mapping.get(ri.getClientComponent()).getName(), mapping.get(ri.getClientComponent()).asInternal().getRequiredPorts().ofType(ri.getRequiredEnd().getType()).getType().getName()) .to(mapping.get(ri.getServerComponent()).getName(), mapping.get(ri.getServerComponent()).getProvidedPorts().ofType(ri.getProvidedEnd().getType()).getType().getName()) .ofType(ri.getType().getName())); }else{ rib.put(name, aRelationshipInstance() .named(name) .from(mapping.get(ri.getClientComponent()).getName(), mapping.get(ri.getClientComponent()).asInternal().getRequiredPorts().ofType(ri.getRequiredEnd().getType()).getType().getName()) .to(ri.getServerComponent().getName(), ri.getProvidedEnd().getType().getName()) rib.put(name, aRelationshipInstance() .named(name) .from(ri.getClientComponent().getName(), ri.getRequiredEnd().getName()) .to(mapping.get(ri.getServerComponent()).getName(), mapping.get(ri.getServerComponent()).getProvidedPorts().ofType(ri.getProvidedEnd().getType()).getType().getName()) .ofType(ri.getType().getName()));
private RequiredPortInstance findClientPort(Deployment container) { final InternalComponentInstance client = findClient(container); final RequiredPort portType = client.getType().getRequiredPorts().firstNamed(clientPort); if(portType == null){ final String error = String.format("Unable to find the required port type '%s'", clientPort); throw new IllegalStateException(error); } final RequiredPortInstance port = client.getRequiredPorts().ofType(portType); if (port == null) { final String error = String.format("Unable to find the required port instance '%s' in '%s'", clientPort, client); throw new IllegalStateException(error); } return port; }
/** * 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); } }
@Override public void dispatchTo(Visitor visitor, InternalComponentInstance internalInstance) { dispatchTo(visitor, (ComponentInstance<? extends Component>) internalInstance); for (RequiredPortInstance port : internalInstance.getRequiredPorts()) { visitor.visitRequiredPortInstance(port); } visitor.visitRequiredExecutionPlatformInstance(internalInstance.getRequiredExecutionPlatform()); }
public ExecuteInstance(String name, InternalComponentInstance instance, ProvidedExecutionPlatformInstance platform) { this(name, instance.getRequiredExecutionPlatform(), platform); }
/** * Find all the components that can possibly host the given internal * component instance * * @param component the component that needs a host * @return the list of components that can be host */ private List<ComponentInstance<?>> findAllCandidateHosts(InternalComponentInstance component) { assert component != null: "Unable to find host for 'null'"; final List<ComponentInstance<?>> candidates = new LinkedList<ComponentInstance<?>>(); for (ComponentInstance<?> eachComponent: component.getDeployment().getComponentInstances()) { if (eachComponent.canHost(component.getType())) { candidates.add(eachComponent); } } return candidates; }
protected void configureBindingOfImpactedComponents(Set<ComponentInstance> listOfAllComponentImpacted, Map<InternalComponentInstance, InternalComponentInstance> duplicatedGraph){ for(InternalComponentInstance ici: duplicatedGraph.values()){ for(ProvidedPortInstance ppi: ici.getProvidedPorts()){ RelationshipInstanceGroup rig=currentModel.getRelationshipInstances().whereEitherEndIs(ppi); manageDuplicatedRelationships(rig, listOfAllComponentImpacted); } for(RequiredPortInstance rpi: ici.getRequiredPorts()){ RelationshipInstanceGroup rig=currentModel.getRelationshipInstances().whereEitherEndIs(rpi); manageDuplicatedRelationships(rig, listOfAllComponentImpacted); } } }
private void resolveDependencies(Deployment target, InternalComponentInstance instance) { for (RequiredPortInstance clientPort : instance.getRequiredPorts()) { getLibrary().bind(target, clientPort); } } }
public void drawEdgesFromDeploymentModel(Deployment dm, ArrayList<Vertex> v) { for (ComponentInstance x : dm.getComponentInstances()) { if (x instanceof InternalComponentInstance) { InternalComponentInstance ix = (InternalComponentInstance) x; if (ix.getRequiredExecutionPlatform() != null) { Vertex v1 = findVertex(ix.getName(), v); Vertex v2 = findVertex(ix.getRequiredExecutionPlatform().getName(), v); Edge e = new Edge("dest" + ix.getName(), "destination"); createEdge(e, v1, v2); } }//TODO else } for (RelationshipInstance bi : dm.getRelationshipInstances()) { Vertex v1 = findVertex(bi.getRequiredEnd().getOwner().getName(), v); Vertex v2 = findVertex(bi.getProvidedEnd().getOwner().getName(), v); Edge e; if (!bi.getRequiredEnd().getType().isMandatory()) { e = new Edge(bi.getName(), "optional", bi); } else { e = new Edge(bi.getName(), "mandatory", bi); } createEdge(e, v1, v2); } }
private RequiredExecutionPlatformInstance rejectIfInvalid(RequiredExecutionPlatformInstance platform) { if (platform == null) { final String error = String.format("Error in internal component instance '%s'! ('null' cannot be the required execution platform)", getQualifiedName()); throw new IllegalArgumentException(error); } if (!platform.getType().equals(this.getType().getRequiredExecutionPlatform())) { final String error = String.format("Error in internal component instance '%s'! Required execution platform has a wrong type (expected: '%s' but found '%s')", getQualifiedName(), getType().getRequiredExecutionPlatform().getQualifiedName(), platform.getType().getQualifiedName()); throw new IllegalArgumentException(error); } return platform; }
/** * @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; } }