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; }
public DefaultListModel fillList(){ DefaultListModel lm=new DefaultListModel(); for(ExternalComponent n:dmodel.getComponents().onlyExternals()){ lm.addElement(n.getName()); } for(Component n:dmodel.getComponents()){ lm.addElement(n.getName()); } for(Relationship b:dmodel.getRelationships()){ lm.addElement(b.getName()); } return lm; }
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; } }
private ComponentInstance<? extends Component> findHost(Deployment container) { final ComponentInstance<? extends Component> host = container.getComponentInstances().firstNamed(hostName); if (host == null) { final String error = String.format("Unable to find the host component named '%s'!", hostName); throw new IllegalStateException(error); } return host; }
public synchronized void commitModifications(List<String> modifications) { for (String modi : modifications) { String[] parsed = modi.split("\\s+"); if ("add".equals(parsed[0])) { if ("in".equals(parsed[4]) && "root".equals(parsed[5]) && "nodeTypes".equals(parsed[6])) { // FIXME: We should know which provider is responsible for the new VM we add! final Provider provider = new Provider("Missing Provider"); repo.getRoot().getProviders().add(provider); repo.getRoot().getComponents().add(new VM(parsed[3], provider)); } } } }
@Override protected List<Component> collectCandidates(Deployment deployment) { List<Component> candidates = new ArrayList<Component>(); for (Component node : deployment.getComponents()) { if (isCandidate(component, node)) { candidates.add(node); } } return candidates; }
prepareComponents(new ComponentInstanceGroup(diff.getAddedComponents()), targetModel.getRelationshipInstances()); configureWithRelationships(new RelationshipInstanceGroup(diff.getAddedRelationships())); configureSaas(new ComponentInstanceGroup<InternalComponentInstance>(diff.getAddedComponents())); configureWithPuppet(targetModel.getComponentInstances().onlyInternals()); generatePuppetManifestAndConfigure(); if(targetModel.getProperties().get("sla_url") != null && targetModel.getProperties().get("agreement_id") != null){ Boolean status=startSLA(targetModel.getProperties().get("sla_url").getValue(),targetModel.getProperties().get("agreement_id").getValue()); if(status){ journal.log(Level.INFO, ">> SLA management started");
@Override public Void applyTo(Deployment deployment) { RelationshipInstanceGroup bindings = deployment.getRelationshipInstances().whereEitherEndIs(port); for(RelationshipInstance binding: bindings) { deployment.getRelationshipInstances().remove(binding); } return NOTHING; }
/** * Convert a Deployment model from CloudMl in a format * compatible with MODAClouds Monitoring Platform's APIs * * @param deployment the deployment model to convert */ public static Model fromCloudmlToModaMP(Deployment deployment) { //get the relevant part of the model //create a new list for avoid changes in the original one ComponentInstanceGroup instances = new ComponentInstanceGroup(); instances.addAll(deployment.getComponentInstances()); ProviderGroup providers = new ProviderGroup(); providers.addAll(deployment.getProviders()); //call the actual translator return getModelUpdates(instances, providers); }
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)); } } }
private void shutdownInternalComponentInstance(Deployment target) { getLibrary().stop(target, artefactInstance); final ExecuteInstance execution = target.getExecuteInstances().withSubject(artefactInstance); assert execution != null: String.format("There should be an execute instance whose required end points to '%s'", artefactInstance.getName()); target.getExecuteInstances().remove(execution); target.getComponentInstances().remove(artefactInstance); }
/** * Find all the component that can be used as service providers for the * given required port * * @param requiredPort the port for which a provider is needed * @return the list of candidates service providers */ private List<ComponentInstance<?>> findAllCandidateProviders(RequiredPortInstance requiredPort) { assert requiredPort != null: "Unable to find service providers for 'null'"; final List<ComponentInstance<?>> candidates = new LinkedList<ComponentInstance<?>>(); final Deployment deployment = requiredPort.getDeployment(); for (Relationship eachRelationship: deployment.getRelationships()) { if (eachRelationship.getRequiredEnd().equals(requiredPort.getType())) { final ProvidedPort serverType = eachRelationship.getProvidedEnd(); for (ComponentInstance<?> eachComponent: deployment.getComponentInstances()) { if (eachComponent.getType().canProvide(serverType)) { candidates.add(eachComponent); } } } } return candidates; }
@Override public Deployment build() { Deployment model = new Deployment(getName()); super.prepare(model); for(ProviderBuilder provider: providers) { model.getProviders().add(provider.build()); } for (ComponentBuilder<? extends Component, ? extends ComponentBuilder<?, ?>> builder : components) { builder.integrateIn(model); } for(ComponentInstanceBuilder<? extends ComponentInstance<? extends Component>, ? extends ComponentInstanceBuilder<?,?>> builder: componentInstances) { builder.integrateIn(model); } for (RelationshipBuilder relationship: relationships) { relationship.integrateIn(model); } for (RelationshipInstanceBuilder builder: relationshipInstances) { builder.integrateIn(model); } return model; }
@Override protected List<Relationship> collectCandidates(Deployment deployment) { final ArrayList<Relationship> candidates = new ArrayList<Relationship>(); for (Relationship binding : deployment.getRelationships()) { if (isRelevant(requiredPort, binding)) { candidates.add(binding); } } return candidates; }
@Override public void integrateIn(Deployment container) { final InternalComponentInstance result = findType(container).instantiate(getName()); setupProperties(result); setupResources(result); container.getComponentInstances().add(result); container.deploy(result, findHost(container)); }
public SimpleModelRepo(){ root = new Deployment(); }
protected Provider findProvider(Deployment container) { final Provider provider = container.getProviders().firstNamed(providerName); if (provider == null) { final String error = String.format("Unable to find the provider named '%s'", providerName); throw new IllegalStateException(error); } return provider; }
/** * Compares the executeInstances between the current and target model */ public void compareExecutes() { journal.log(Level.INFO, ">> Comparing Executes Instances ..."); Boolean match = false; for (ExecuteInstance ei : currentDM.getExecuteInstances()) { secondloop: { for (ExecuteInstance ei2 : targetDM.getExecuteInstances()) { match = ei.equals(ei2); if (ei.equals(ei2)) { matchingExecutes.put(ei, ei2); break secondloop; } } } if (!match) { removedExecutes.add(ei); } } //add the rest addExecutes(); }
@Override public InternalComponentInstance applyTo(Deployment deployment) { final ComponentInstance<? extends Component> newHost = getLibrary().findAlternativeDestinationFor(deployment, instance); final ExecuteInstance execution = deployment.getExecuteInstances().withSubject(instance); assert execution != null: String.format("There should be an execute instance whose required end points to '%s'", instance.getName()); deployment.getExecuteInstances().remove(execution); deployment.deploy(instance, newHost); return instance; }