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 RelationshipInstanceGroup whereEitherEndIs(PortInstance<? extends Port> port) { final RelationshipInstanceGroup selection = new RelationshipInstanceGroup(); for (RelationshipInstance instance: this) { if (instance.eitherEndIs(port)) { selection.add(instance); } } return selection; }
@Override public Void applyTo(Deployment deployment) { RelationshipInstanceGroup bindings = deployment.getRelationshipInstances().whereEitherEndIs(port); for(RelationshipInstance binding: bindings) { deployment.getRelationshipInstances().remove(binding); } return NOTHING; }
public boolean isBound() { return !getDeployment().getRelationshipInstances().whereEitherEndIs(this).isEmpty(); }
/** * 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!"); } }
@Override public boolean add(RelationshipInstance instance) { if (firstNamed(instance.getName()) != null) { //final String error = String.format("Relationship instance name must be unique! There is already a relationhip instance named '%s'.", instance.getName()); //throw new IllegalStateException(error); return false; } instance.getOwner().set(Deployment.this); return super.add(instance); }
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; }
setAllEnvVarComponent(targetModel); prepareComponents(new ComponentInstanceGroup(diff.getAddedComponents()), targetModel.getRelationshipInstances()); configureWithRelationships(new RelationshipInstanceGroup(diff.getAddedRelationships())); configureSaas(new ComponentInstanceGroup<InternalComponentInstance>(diff.getAddedComponents())); configureWithPuppet(targetModel.getComponentInstances().onlyInternals());
@Override public boolean remove(Object o) { if (o instanceof RelationshipInstance) { ((RelationshipInstance) o).getOwner().discard(); } return super.remove(o); } }
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 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 InternalComponentInstanceGroup clientComponents() { if (getOwner().isUndefined()) { return new InternalComponentInstanceGroup(); } return getDeployment().getRelationshipInstances().clientsOf(this); }
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; }
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; } }
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); }
buildPaas(instance, relationships.toList());
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; }
setAllEnvVarComponent(currentModel); prepareComponents(new ComponentInstanceGroup(diff.getAddedComponents()), targetModel.getRelationshipInstances()); configureWithRelationships(new RelationshipInstanceGroup(diff.getAddedRelationships())); configureSaas(new ComponentInstanceGroup<InternalComponentInstance>(diff.getAddedComponents())); configureWithPuppet(targetModel.getComponentInstances().onlyInternals());