private String componentFormatting(ComponentInstance<? extends Component> subject) { return "label=\"" + subject.getName() + "\""; }
private String vmFormatting(ComponentInstance<? extends Component> subject) { return "label=\"" + subject.getName() + "\", style=\"filled\""; }
@Override public boolean equals(Object other) { if (other == null) { return false; } if (other instanceof ComponentInstance) { ComponentInstance otherCompInst = (ComponentInstance) other; Boolean match = getName().equals(otherCompInst.getName()) && type.equals(otherCompInst.getType()); return match; } else { return false; } }
private ComponentInstance<? extends Component> rejectIfInvalid(ComponentInstance<? extends Component> host) { if (host == null) { throw new IllegalArgumentException("'null' is not a valid destination for installation"); } if (!host.canHost(type)) { final String error = String.format("Illegal installation: '%s' cannot host component of type '%s'", host.getName(), type.getName()); throw new IllegalArgumentException(error); } return host; }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("Instance " + getName() + " : " + getType().getName()); for(PortInstance p : this.getProvidedPorts()) builder.append("-Provided port:"+p.getName()); return builder.toString(); }
@Override public String getQualifiedName() { return getOwner().getName() + "::" + getName(); }
public String calculateExecutionPlatformIdentifier(ExecutionPlatformInstance<? extends ExecutionPlatform> epi) { return String.format("%s-%s", epi.getOwner().get().getName(), epi.getName()); }
public boolean hasSubject(InternalComponentInstance component) { return getRequiredEnd().getOwner().get().getName().equals(component.getName()); }
@Override public boolean add(T element) { element.getOwner().set(Deployment.this); if (firstNamed(element.getName()) != null) { //final String error = String.format("Component instance name must be unique! There is already a component instance named '%s'.", element.getName()); //throw new IllegalStateException(error); return false; } return super.add(element); }
public boolean replace(T element){ if (firstNamed(element.getName()) != null) { super.remove(element); } element.getOwner().set(Deployment.this); return super.add(element); }
/** * Convert the given CloudML deployment model into a TRIO system * * @param model the CloudML model to be converted * * @return an equivalent Trio system */ public System asTrioSystem(Deployment model) { requireValidDeployment(model); final Map<String, List<String>> tagged = prepareTagMap(); final ArrayList<Component> trioComponents = new ArrayList<Component>(); for (ComponentInstance each: model.getComponentInstances()) { extractTags(each, tagged); trioComponents.add(new Component(each.getName(), extractRequirement.from(each))); } return new System(trioComponents, buildTags(tagged)); }
@Override public Requirement from(ComponentInstance<?> instance) { requireValidComponent(instance); Requirement requirements = nothing(); if (instance.isInternal()) { final InternalComponentInstance internalInstance = instance.asInternal(); for (RequiredPortInstance eachDependency: internalInstance.getRequiredPorts()) { if (eachDependency.isBound()) { requirements = requirements.and(require(eachDependency.findProvider().getName())); } } requirements = requirements.and(require(internalInstance.getHost().getName())); } return requirements; }
/** * Build a disjunction between all the providers that can meet the * requirements of the given requiredPort * * @param dependency the dependency that must satisfied * @return a disjunction (i.e., logical or) between all the service * providers that satisfies the given dependencies. */ private Requirement anyMatchingProvider(RequiredPortInstance dependency) { assert dependency != null: "Unable to find service providers for 'null'"; Requirement disjunction = nothing().not(); for (ComponentInstance<?> eachProvider: findAllCandidateProviders(dependency)) { disjunction = disjunction.or(require(eachProvider.getName())); } assert disjunction != null: "Should never return null"; return disjunction; }
/** * Compute the disjunction of all possible host that matches the given * component * * @param component the internal component whose candidate hosts are needed. * * @return a disjunction (OR) between all candidates hosts */ private Requirement anyMatchingHost(final InternalComponentInstance component) { assert component != null: "Unable to find hosts for 'null'"; Requirement disjunction = nothing().not(); for (ComponentInstance<?> eachHost: findAllCandidateHosts(component)) { disjunction = disjunction.or(require(eachHost.getName())); } assert disjunction != null: "Should never return null"; return disjunction; }
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()); } }
public String toString(){ String result=" Component instances:\n"; for(ComponentInstance c: components){ if(c.isExternal()){ if(c.asExternal().isVM()){ result+=" VM-> "+c.asExternal().asVM().getId()+"::"+c.getName()+"\n"; }else{ result+=" External component-> "+c.getQualifiedName()+"\n"; } }else{ result+=" Instance component-> "+c.getQualifiedName()+"\n"; } } return result; } }
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()); } }
@Override public InternalComponentInstance applyTo(Deployment target) { final String instanceName = getLibrary().createUniqueComponentInstanceName(target, type); InternalComponentInstanceBuilder builder = anInternalComponentInstance() .named(instanceName) .ofType(type.getName()) .hostedBy(host.getName()); builder.integrateIn(target); InternalComponentInstance instance = target.getComponentInstances().onlyInternals().firstNamed(instanceName); resolveDependencies(target, instance); return instance; }
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(); }
@Override public ComponentInstance applyTo(Deployment target) { ComponentInstance result=null; if(instance.isInternal()){ final String instanceName = getLibrary().createUniqueComponentInstanceName(target, instance.asInternal().getType()); InternalComponentInstanceBuilder builder = anInternalComponentInstance() .named(instanceName) .ofType(instance.asInternal().getType().getName()) .hostedBy(host.getName()); builder.integrateIn(target); result = target.getComponentInstances().onlyInternals().firstNamed(instanceName); } if(instance.isExternal()){ result=getLibrary().provision(target, instance.getType()); } return result; }