public final boolean isExternal() { return !isInternal(); }
@SuppressWarnings("unchecked") public final ExternalComponentInstance<ExternalComponent> asExternal() { if (isInternal()) { throw new IllegalStateException("Unable to convert an internal component instance into an external one"); } return (ExternalComponentInstance<ExternalComponent>) this; }
public boolean canBeUninstalled() { return !isUsed() && isInternal(); }
public InternalComponentInstanceGroup onlyInternals() { final InternalComponentInstanceGroup internalInstances = new InternalComponentInstanceGroup(); for (final T instance: this) { if (instance.isInternal()) { internalInstances.add(instance.asInternal()); } } return internalInstances; }
/** * Extract the tag that can be identified on the given component instance. * * @param componentInstance the component whose tags are needed * @param tagged the already initialised maps of tags, to be filled in */ private void extractTags(ComponentInstance componentInstance, Map<String, List<String>> tagged) { assert componentInstance != null: "Unable to extract tags from 'null'"; assert !tagged.isEmpty(): "The map of tag must have been initialized"; if (componentInstance.isExternal()) { tagged.get(EXTERNAL.getLabel()).add(componentInstance.getName()); if (componentInstance.asExternal().isVM()) { tagged.get(VM.getLabel()).add(componentInstance.getName()); } } if (componentInstance.isInternal()) { tagged.get(INTERNAL.getLabel()).add(componentInstance.getName()); } if (isService(componentInstance)) { tagged.get(SERVICE.getLabel()).add(componentInstance.getName()); } else { tagged.get(NOT_SERVICE.getLabel()).add(componentInstance.getName()); } }
/** * @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; } }
private void addRelationships() { addedRelationships = new ArrayList<RelationshipInstance>(targetDM.getRelationshipInstances()); addedRelationships.removeAll(matchingRelationships.values()); for (RelationshipInstance ni : addedRelationships) { int i = currentDM.getComponentInstances().toList().indexOf(ni.getRequiredEnd().getOwner().get()); if (i >= 0) { ComponentInstance a = currentDM.getComponentInstances().toList().get(i); if (a.isInternal()) { int j = ((InternalComponentInstance) a).getRequiredPorts().toList().indexOf(ni.getRequiredEnd()); ni.setRequiredEnd(((InternalComponentInstance) a).getRequiredPorts().toList().get(j)); } } i = currentDM.getComponentInstances().toList().indexOf(ni.getProvidedEnd().getOwner().get()); if (i >= 0) { ComponentInstance a = currentDM.getComponentInstances().toList().get(i); int j = a.getProvidedPorts().toList().indexOf(ni.getProvidedEnd()); List<ProvidedPortInstance> l = a.getProvidedPorts().toList(); ni.setProvidedEnd(l.get(j)); } } }
@Override public Requirement from(ComponentInstance<?> component) { requireValidComponent(component); Requirement requirements = nothing(); if (component.isInternal()) { final InternalComponentInstance internalInstance = component.asInternal(); for (RequiredPortInstance eachDependency: internalInstance.getRequiredPorts()) { requirements = requirements.and(anyMatchingProvider(eachDependency)); } requirements = requirements.and(anyMatchingHost(internalInstance)); } return requirements; }
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; }
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()); } }
@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; }
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(); }
if (host.isInternal()) { buildExecutes(host.asInternal()); journal.log(Level.INFO, ">> Installing host: " + host.getName());
if (serverComponent.isInternal()) { coordinator.updateStatusInternalComponent(serverComponent.getName(), State.INSTALLED.toString(), CloudAppDeployer.class.getName()); configure(jc, n, owner, configurationCommand, r.getRequireCredentials()); if (serverComponent.isInternal()) { coordinator.updateStatusInternalComponent(serverComponent.getName(), State.CONFIGURED.toString(), CloudAppDeployer.class.getName()); start(jc, n, owner, startCommand); if (serverComponent.isInternal()) { coordinator.updateStatusInternalComponent(serverComponent.getName(), State.RUNNING.toString(), CloudAppDeployer.class.getName());
@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; }