@Override public boolean equals(Object other) { if (other instanceof BindingInstance) { BindingInstance otherBinding = (BindingInstance) other; return (client.equals(otherBinding.getClient()) && server.equals(otherBinding.getServer())); } else { return false; } }
private void addBindings(){ addedBindings = new ArrayList<BindingInstance>(targetDM.getBindingInstances()); addedBindings.removeAll(matchingBindings.values()); for(BindingInstance ni : addedBindings){ int i=currentDM.getArtefactInstances().indexOf(ni.getClient().getOwner()); if(i >= 0){ ArtefactInstance a=currentDM.getArtefactInstances().get(i); int j=a.getRequired().indexOf(ni.getClient()); ni.setClient(a.getRequired().get(j)); } i=currentDM.getArtefactInstances().indexOf(ni.getServer().getOwner()); if(i >= 0){ ArtefactInstance a=currentDM.getArtefactInstances().get(i); int j=a.getProvided().indexOf(ni.getServer()); ni.setServer(a.getProvided().get(j)); } } }
/** * Find the destination of an artefactInstance * @param a an instance of artefact * @return a nodeInstance */ private NodeInstance findDestination(ArtefactInstance a){ if(a.getDestination() != null){ return a.getDestination(); }else{ for(BindingInstance b: currentModel.getBindingInstances()){ if(a.getRequired().contains(b.getClient()) && !b.getClient().getType().getIsRemote()) return b.getServer().getOwner().getDestination(); if(a.getProvided().contains(b.getServer()) && !b.getServer().getType().getIsRemote()) return b.getClient().getOwner().getDestination(); } return null; } }
private void unconfigureBinding(BindingInstance b) { if(b.getClient().getType().getIsRemote()){ ClientPortInstance client=b.getClient(); ServerPortInstance server=b.getServer(); Resource clientResource=b.getType().getClientResource(); Resource serverResource=b.getType().getServerResource(); //client resources unconfigureWithIP(clientResource,client); //server resources unconfigureWithIP(serverResource,server); } }
/** * Build the paas of an artefact instance * @param x An artefactInstance * @throws MalformedURLException */ private void buildPaas(ArtefactInstance x, List<BindingInstance> bindings) { NodeInstance ownerNode = x.getDestination(); Node n=ownerNode.getType(); Connector jc; jc=ConnectorFactory.createConnector(n.getProvider()); //jc=new JCloudsConnector(n.getProvider().getName(), n.getProvider().getLogin(), n.getProvider().getPasswd()); for(BindingInstance bi : bindings){ if(!bi.getClient().getType().getIsOptional() && x.getRequired().contains(bi.getClient())){ ServerPortInstance p=bi.getServer(); NodeInstance owner=p.getOwner().getDestination(); if(owner == null) owner=ownerNode; if(!alreadyDeployed.contains(p.getOwner())){ jc.execCommand(owner.getId(), p.getOwner().getType().getResource().getRetrievingResourceCommand() ,"ubuntu",n.getPrivateKey()); jc.execCommand(owner.getId(), p.getOwner().getType().getResource().getDeployingResourceCommand(),"ubuntu",n.getPrivateKey()); String configurationCommand=p.getOwner().getType().getResource().getConfigurationResourceCommand(); String startCommand=p.getOwner().getType().getResource().getStartResourceCommand(); configureAndStart(jc, n, owner, configurationCommand, startCommand); alreadyDeployed.add(p.getOwner()); alreadyStarted.add(p.getOwner()); } } } jc.closeConnection(); }
/** * Configure Artefacts according to the bindings * @param dm a deployment model * @throws MalformedURLException */ private void configureWithBindings(List<BindingInstance> bindings) { //Configure on the basis of the bindings //parameters transmitted to the configuration scripts are "ip ipDestination portDestination" for(BindingInstance bi : bindings){ if(bi.getClient().getType().getIsRemote()){ ClientPortInstance client=bi.getClient(); ServerPortInstance server=bi.getServer(); Resource clientResource=bi.getType().getClientResource(); Resource serverResource=bi.getType().getServerResource(); String destinationIpAddress=server.getOwner().getDestination().getPublicAddress(); int destinationPortNumber=server.getType().getPortNumber(); String ipAddress=client.getOwner().getDestination().getPublicAddress(); //client resources configureWithIP(clientResource,client,destinationIpAddress,ipAddress,destinationPortNumber); //server resources configureWithIP(serverResource,server,destinationIpAddress,ipAddress,destinationPortNumber); } } }
kb.setName(b.getName()); kb.setClient(clientPortInstances.get(b.getClient().getName())); kb.setServer(serverPortInstances.get(b.getServer().getName())); kb.setType(bindings.get(b.getType().getName()));
public void drawEdgesFromDeploymentModel(DeploymentModel dm, ArrayList<Vertex> v){ for(ArtefactInstance x : dm.getArtefactInstances()){ if(x.getDestination() != null){ Vertex v1=findVertex(x.getName(), v); Vertex v2=findVertex(x.getDestination().getName(), v); Edge e=new Edge("dest"+x.getName(), "destination"); createEdge(e, v1, v2); } } for(BindingInstance bi: dm.getBindingInstances()){ Vertex v1=findVertex(bi.getClient().getOwner().getName(), v); Vertex v2=findVertex(bi.getServer().getOwner().getName(), v); Edge e; if(bi.getClient().getType().getIsOptional()) e=new Edge(bi.getName(), "optional",bi); else e=new Edge(bi.getName(), "mandatory",bi); createEdge(e, v1, v2); } }