@Override public Void applyTo(Deployment deployment) { RelationshipInstanceGroup bindings = deployment.getRelationshipInstances().whereEitherEndIs(port); for(RelationshipInstance binding: bindings) { deployment.getRelationshipInstances().remove(binding); } return NOTHING; }
/** * Compares the relationships between the targeted and the current * deployment model */ public void compareRelationships() { journal.log(Level.INFO, ">> Comparing relationships ..."); Boolean match = false; for (RelationshipInstance ni : currentDM.getRelationshipInstances()) { secondloop: { for (RelationshipInstance ni2 : targetDM.getRelationshipInstances()) { match = ni.equals(ni2); if (ni.equals(ni2)) { matchingRelationships.put(ni, ni2); break secondloop; } } } if (!match) { removedRelationships.add(ni); } } //add the rest addRelationships(); }
public List<RequiredPortInstance> findClients() { final RelationshipInstanceGroup relationships = getDeployment().getRelationshipInstances().whereEitherEndIs(this); if (relationships.isEmpty()) { final String message = String.format("provided port '%s' is not yet bound to any client", getQualifiedName()); throw new IllegalArgumentException(message); } final List<RequiredPortInstance> clients = new ArrayList<RequiredPortInstance>(); for (RelationshipInstance relationship : relationships) { clients.add(relationship.getRequiredEnd()); } return clients; }
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); } } }
public ProvidedPortInstance findServerPort() { final RelationshipInstanceGroup relationships = getDeployment().getRelationshipInstances().whereEitherEndIs(this); if (relationships.isEmpty()) { final String message = String.format("client port '%s' is not yet bound to any server", getName()); throw new IllegalArgumentException(message); } return relationships.toList().get(0).getProvidedEnd(); }
public String createUniqueRelationshipInstanceName(Deployment deployment, Relationship type) { String format = prepareFormat(type.getName()); return createUniqueName(deployment.getRelationshipInstances(), format); }
public boolean isBound() { return !getDeployment().getRelationshipInstances().whereEitherEndIs(this).isEmpty(); }
public InternalComponentInstanceGroup clientComponents() { if (getOwner().isUndefined()) { return new InternalComponentInstanceGroup(); } return getDeployment().getRelationshipInstances().clientsOf(this); }
public void relationshipInstanceToPOJO(net.cloudml.core.RelationshipInstance kRelationshipInstance) { checkForNull(kRelationshipInstance, "Cannot convert null!"); if (kRelationshipInstance.getRequiredPortInstance() == null) { throw new IllegalArgumentException("a relationship instance required at least a required port instance"); } if (kRelationshipInstance.getProvidedPortInstance() == null) { throw new IllegalArgumentException("a relationship instance required at least a provided port instance"); } net.cloudml.core.RequiredPortInstance r = kRelationshipInstance.getRequiredPortInstance(); net.cloudml.core.ProvidedPortInstance p = kRelationshipInstance.getProvidedPortInstance(); if (r.getName() == null) { throw new IllegalArgumentException("Required port need a name"); } if (p.getName() == null) { throw new IllegalArgumentException("Provided port need a name"); } RelationshipInstance b = new RelationshipInstance(kRelationshipInstance.getName(), requiredPortInstances.get(r.getName()), providedPortInstances.get(p.getName()), relationships.get(kRelationshipInstance.getType().getName())); model.getRelationshipInstances().add(b); }
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 void integrateIn(Deployment container) { final RelationshipInstance relationship = new RelationshipInstance(getName(), findClientPort(container), findServerPort(container), findType(container)); super.prepare(relationship); container.getRelationshipInstances().add(relationship); }
public Deployment merge(String path){ InputStream instream = null; try { instream = new FileInputStream(path); } catch (FileNotFoundException e) { e.printStackTrace(); } Deployment target = (Deployment) new JsonCodec().load(instream); if (isDeploymentLoaded()) { deploy.getComponents().replaceAll(target.getComponents()); deploy.getRelationships().replaceAll(target.getRelationships()); //TODO: Check if names are unique deploy.getComponentInstances().replaceAll(target.getComponentInstances()); deploy.getExecuteInstances().replaceAll(target.getExecuteInstances()); deploy.getProviders().replaceAll(target.getProviders()); deploy.getRelationshipInstances().replaceAll(target.getRelationshipInstances()); }else{ deploy=target; } initCoordinator(); return deploy; }
public Deployment clone(){ Deployment tmp=new Deployment(); tmp.getComponents().addAll(this.getComponents()); tmp.getComponentInstances().addAll(this.getComponentInstances()); tmp.getExecuteInstances().addAll(this.getExecuteInstances()); tmp.getProviders().addAll(this.getProviders()); tmp.getRelationshipInstances().addAll(this.getRelationshipInstances()); tmp.getClouds().addAll(this.getClouds()); tmp.getRelationships().addAll(this.getRelationships()); tmp.setName(this.getName()); return tmp; }
prepareComponents(new ComponentInstanceGroup(diff.getAddedComponents()), targetModel.getRelationshipInstances()); configureWithRelationships(new RelationshipInstanceGroup(diff.getAddedRelationships())); configureSaas(new ComponentInstanceGroup<InternalComponentInstance>(diff.getAddedComponents()));
/** * Update the currentModel with the targetModel and preserve all the CPSM * metadata * * @param diff a model comparator */ public void updateCurrentModel(CloudMLModelComparator diff) { if (diff != null) { currentModel.getComponents().addAll(targetModel.getComponents()); currentModel.getRelationships().addAll(targetModel.getRelationships()); currentModel.getComponentInstances().removeAll(diff.getRemovedComponents()); currentModel.getRelationshipInstances().removeAll(diff.getRemovedRelationships()); currentModel.getComponentInstances().removeAll(diff.getRemovedECs().keySet()); currentModel.getExecuteInstances().removeAll(diff.getRemovedExecutes()); alreadyDeployed.removeAll(diff.getRemovedComponents()); alreadyStarted.removeAll(diff.getRemovedComponents()); currentModel.getComponentInstances().replaceAll(diff.getAddedComponents()); currentModel.getRelationshipInstances().replaceAll(diff.getAddedRelationships()); currentModel.getComponentInstances().replaceAll(diff.getAddedECs()); currentModel.getExecuteInstances().replaceAll(diff.getAddedExecutes()); } else { throw new IllegalArgumentException("Cannot update current model without comparator!"); } }
private void saveMetadata(Deployment deploy2) { if (isDeploymentLoaded()) { diff = new CloudMLModelComparator(deploy, deploy2); diff.compareCloudMLModel(); deploy.setName(deploy2.getName()); deploy.getComponents().addAll(deploy2.getComponents()); deploy.getRelationships().addAll(deploy2.getRelationships()); deploy.getRelationshipInstances().removeAll(diff.getRemovedRelationships()); deploy.getExecuteInstances().removeAll(diff.getRemovedExecutes()); deploy.getComponentInstances().removeAll(diff.getRemovedECs().keySet()); deploy.getComponentInstances().removeAll(diff.getRemovedComponents()); deploy.getRelationshipInstances().replaceAll(diff.getAddedRelationships()); deploy.getComponentInstances().replaceAll(diff.getAddedECs()); deploy.getExecuteInstances().replaceAll(diff.getAddedExecutes()); deploy.getComponentInstances().replaceAll(diff.getAddedComponents()); } else { deploy = deploy2; } }
@Override public void dispatchTo(Visitor visitor, Deployment deployment) { for (Provider provider : deployment.getProviders()) { provider.accept(visitor); } for (Component component : deployment.getComponents()) { component.accept(visitor); } for (ComponentInstance<? extends Component> instance : deployment.getComponentInstances()) { instance.accept(visitor); } for (Relationship relationship : deployment.getRelationships()) { relationship.accept(visitor); } for (RelationshipInstance instance : deployment.getRelationshipInstances()) { instance.accept(visitor); } for(ExecuteInstance execute: deployment.getExecuteInstances()) { execute.accept(visitor); } for (Cloud cloud : deployment.getClouds()) { cloud.accept(visitor); } }
/** * Find the destination of an ComponentInstance * * @param a an instance of component * @return a VMInstance */ private ExternalComponentInstance findDestinationWhenNoRequiredExecutionPlatformSpecified(InternalComponentInstance a) { if (getDestination(a) != null) { return getDestination(a); } else { for (RelationshipInstance b : currentModel.getRelationshipInstances()) { if (a.getRequiredPorts().contains(b.getRequiredEnd()) && b.getRequiredEnd().getType().isLocal()) { return getDestination(b.getProvidedEnd().getOwner().get()); } if (a.getProvidedPorts().contains(b.getProvidedEnd()) && b.getProvidedEnd().getType().isLocal()) { return getDestination(b.getRequiredEnd().getOwner().get()); } } return null; } }
public net.cloudml.core.CloudMLModel toKMF(Deployment deploy) { kDeploy.setName(deploy.getName()); convertProperties(deploy,kDeploy,factory); providersToKmf(deploy.getProviders().toList()); externalComponentToKmf(deploy.getComponents().onlyExternals().toList()); internalComponentsToKmf(deploy.getComponents().onlyInternals().toList()); externalComponentInstanceToKmf(deploy.getComponentInstances().onlyExternals().toList()); internalComponentInstancesToKmf(deploy.getComponentInstances().onlyInternals().toList()); executesToKmf(deploy.getExecuteInstances().toList()); relationshipsToKmf(deploy.getRelationships()); relationshipInstancesToKmf(deploy.getRelationshipInstances().toList()); return kDeploy; }
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); } }