public String selectClientPortInstance(RelationshipInstance bi) { JPanel panel = new JPanel(); panel.add(new JLabel("Please make a selection:")); DefaultComboBoxModel model = new DefaultComboBoxModel(); for (ComponentInstance ai : dm.getComponentInstances()) { if (ai instanceof InternalComponentInstance) { for (RequiredPortInstance ci : ((InternalComponentInstance) ai).getRequiredPorts()) { System.out.println(bi.getType().getRequiredEnd() + " #### " + ci.getType()); if (ci.getType().equals(bi.getType().getRequiredEnd())) { model.addElement(ci); } } } } JComboBox comboBox = new JComboBox(model); panel.add(comboBox); int result = JOptionPane.showConfirmDialog(null, panel, "RequiredPort", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); switch (result) { case JOptionPane.OK_OPTION: bi.setRequiredEnd((RequiredPortInstance) comboBox.getSelectedItem()); return ((RequiredPortInstance) comboBox.getSelectedItem()).getOwner().getName(); } return ""; }
@Override public RequiredPortInstance instantiate() { return new RequiredPortInstance(ModelUtils.generateUniqueName(getName()), this); }
private void disconnectRequiredPorts(Deployment deployment) { for (RequiredPortInstance clientPort: artefactInstance.getRequiredPorts()) { if (clientPort.isBound()) { final ComponentInstance<? extends Component> server = clientPort.findProvider(); getLibrary().unbind(deployment, clientPort); if (server.canBeUninstalled()) { getLibrary().uninstall(deployment, (InternalComponentInstance) server); } } } }
@Override protected void handleLackOfCandidate(Deployment deployment, List<Relationship> candidates) { final String message = String.format( "Unable to find any relevant relationship type for client port '%s' of type '%s'", requiredPort.getQualifiedName(), requiredPort.getType().getQualifiedName()); throw new IllegalStateException(message); }
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(); }
@Override public Void applyTo(Deployment deployment) { if (!clientPort.isBound()) { final Relationship bindingType = getLibrary().findRelationshipFor(deployment, clientPort); final String name = getLibrary().createUniqueRelationshipInstanceName(deployment, bindingType); final ProvidedPortInstance serverPort = getLibrary().findProvidedPortFor(deployment, bindingType); if(bindingType == null){ throw new IllegalStateException("No type of relationship found for the client port: "+clientPort.getQualifiedName()); } if(serverPort == null){ throw new IllegalStateException("No Server port for the client port: "+clientPort.getQualifiedName()); } aRelationshipInstance() .named(name) .from(clientPort.getOwner().getName(), clientPort.getType().getName()) .to(serverPort.getOwner().getName(), serverPort.getType().getName()) .ofType(bindingType.getName()) .integrateIn(deployment); } return NOTHING; }
@Override public void validate(Report report) { if (getOwner().isUndefined()) { report.addError("Client port instance has no owner"); } }
public RequiredPortInstance withTypeNamed(String name){ for (RequiredPortInstance port: this) { if (port.getType().getName().equals(name)) { return port; } } return null; }
private void convertAndAddRequiredPortInstances(List<RequiredPortInstance> requiredPortInstances, net.cloudml.core.InternalComponentInstance kai) { checkNull(requiredPortInstances, "Cannot iterate on null"); for (RequiredPortInstance api: requiredPortInstances) { checkNull(api, "Cannot convert null"); net.cloudml.core.RequiredPortInstance kapi = factory.createRequiredPortInstance(); kapi.setName(api.getName()); kapi.setType(requiredPorts.get(calculatePortIdentifier(api.getType()))); //kapi.setType(requiredPorts.get(kai.getType().getName() + "_" + api.getType().getName())); convertProperties(api, kapi, factory); kai.addRequiredPortInstances(kapi); this.requiredPortInstances.put(escapePortInstanceName(api), kapi); } }
public void internalComponentInstanceToPOJO(net.cloudml.core.InternalComponentInstance kInternalComponentInstance) { checkForNull(kInternalComponentInstance, "Cannot convert null!"); InternalComponentInstance ai = new InternalComponentInstance(kInternalComponentInstance.getName(), internalComponents.get(kInternalComponentInstance.getType().getName())); convertProperties(kInternalComponentInstance, ai); internalComponentInstances.put(ai.getName(), ai); initRequiredExecutionPlatformInstance(kInternalComponentInstance, ai); initProvidedExecutionPlatformInstances(kInternalComponentInstance, ai); //TODO: destination convertAndAddProvidedPortInstances(kInternalComponentInstance.getProvidedPortInstances(), ai); RequiredPortInstanceGroup rpig=new RequiredPortInstanceGroup(); for (net.cloudml.core.RequiredPortInstance kapi: kInternalComponentInstance.getRequiredPortInstances()) { RequiredPortInstance api = new RequiredPortInstance(kapi.getName(), requiredPorts.get(ai.getType().getName() + "_" + kapi.getType().getName())); api.getOwner().set(ai); convertProperties(kapi, api); //ai.getRequiredPorts().add(api); rpig.add(api); requiredPortInstances.put(api.getName(), api); } ai.setRequiredPorts(rpig); model.getComponentInstances().add(ai); }
/** * 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; }
public LocalRequiredPortInstanceGroup(Collection<RequiredPortInstance> content) { super(); for (RequiredPortInstance instance : content) { super.add(instance); instance.getOwner().set(InternalComponentInstance.this); } }
public RequiredPortInstance ofType(RequiredPort type) { for (RequiredPortInstance port: this) { if (port.getType().equals(type)) { return port; } } return null; }
.named(name) .from(mapping.get(ri.getClientComponent()).getName(), mapping.get(ri.getClientComponent()).asInternal().getRequiredPorts().ofType(ri.getRequiredEnd().getType()).getType().getName()) .to(mapping.get(ri.getServerComponent()).getName(), mapping.get(ri.getServerComponent()).getProvidedPorts().ofType(ri.getProvidedEnd().getType()).getType().getName()) .named(name) .from(mapping.get(ri.getClientComponent()).getName(), mapping.get(ri.getClientComponent()).asInternal().getRequiredPorts().ofType(ri.getRequiredEnd().getType()).getType().getName()) .to(ri.getServerComponent().getName(), ri.getProvidedEnd().getType().getName()) .named(name) .from(ri.getClientComponent().getName(), ri.getRequiredEnd().getName()) .to(mapping.get(ri.getServerComponent()).getName(), mapping.get(ri.getServerComponent()).getProvidedPorts().ofType(ri.getProvidedEnd().getType()).getType().getName())
/** * 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 WarXmlConfigValet(RelationshipInstance relationshipInstance, Resource configResource){ this.relationshipInstance = relationshipInstance; this.warCompInst = relationshipInstance.getRequiredEnd().getOwner().get(); this.configResource = configResource; }
private void validateRequiredEnd(Report report) { if (!requiredEnd.getType().equals(type.getRequiredEnd())) { final String message = String.format( "illegal relationship '%s' instance that does not match its type (required port found '%s' but expected '%s')", getName(), requiredEnd.getType().getName(), type.getRequiredEnd().getName()); report.addError(message); } }
@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 RequiredPortInstance createClientPort() { return new RequiredPortInstance(clientPort, new RequiredPort("required port type")); }