@Override public boolean equals(Object other) { if (other instanceof ArtefactInstance) { ArtefactInstance otherArt = (ArtefactInstance) other; Boolean match= name.equals(otherArt.getName()) && type.equals(otherArt.getType()); if(destination != null) return name.equals(otherArt.getName()) && type.equals(otherArt.getType()) && destination.equals(otherArt.getDestination()); else return match && (otherArt.getDestination() == null); } else { return false; } }
/** * 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; } }
public ArrayList<Vertex> drawVerticesFromDeploymentModel(DeploymentModel dm){ ArrayList<Vertex> V=new ArrayList<Vertex>(); for(NodeInstance n : dm.getNodeInstances()){ Vertex v= new Vertex(n.getName(), "node",n); V.add(v); createVertice(v); } for(ArtefactInstance x : dm.getArtefactInstances()){ if(x.getDestination() == null){ Vertex v= new Vertex(x.getName(), "platform",x); V.add(v); createVertice(v); }else{ Vertex v= new Vertex(x.getName(), "soft",x); V.add(v); createVertice(v); } properties.setModel(new CPIMTable(V.get(0))); runtimeProperties.setModel(new CPSMTable(V.get(0))); } return V; }
/** * Configure and start SaaS artefacts * @param dm a deployment model * @throws MalformedURLException */ private void configureSaas(List<ArtefactInstance> artefacts) { Connector jc; for(ArtefactInstance x : artefacts){ if(!alreadyStarted.contains(x)){ NodeInstance ownerNode = x.getDestination(); Node n=ownerNode.getType(); jc=ConnectorFactory.createConnector(n.getProvider()); //jc=new JCloudsConnector(n.getProvider().getName(), n.getProvider().getLogin(), n.getProvider().getPasswd()); String configurationCommand=x.getType().getResource().getConfigurationResourceCommand(); String startCommand= x.getType().getResource().getStartResourceCommand(); configureAndStart(jc, n, ownerNode, configurationCommand, startCommand); alreadyStarted.add(x); jc.closeConnection(); } } }
/** * Prepare an artefact before it starts. Retrieves its resources, builds its PaaS and installs it * @param x an ArtefactInstance * @param dm the deployment model used to build the artefact's PaaS * @throws MalformedURLException */ private void prepareAnArtefact(ArtefactInstance x, List<ArtefactInstance> artefacts, List<BindingInstance> bindings) { Connector jc; if(!alreadyDeployed.contains(x) && (x.getDestination() != null)){ NodeInstance ownerNode = x.getDestination(); Node n=ownerNode.getType(); jc=ConnectorFactory.createConnector(n.getProvider()); for(String path : x.getType().getResource().getUploadCommand().keySet()){ jc.uploadFile(path, x.getType().getResource().getUploadCommand().get(path), ownerNode.getId(), "ubuntu", n.getPrivateKey()); } jc.execCommand(ownerNode.getId(), x.getType().getResource().getRetrievingResourceCommand(),"ubuntu",n.getPrivateKey()); alreadyDeployed.add(x); buildPaas(x,bindings); jc.execCommand(ownerNode.getId(), x.getType().getResource().getDeployingResourceCommand(),"ubuntu",n.getPrivateKey()); jc.closeConnection(); } }
private void unconfigureWithIP(Resource r, ArtefactPortInstance i) { Connector jc; if(r != null){ NodeInstance ownerNode = i.getOwner().getDestination(); Node n=ownerNode.getType(); jc=ConnectorFactory.createConnector(n.getProvider()); //jc=new JCloudsConnector(n.getProvider().getName(), n.getProvider().getLogin(), n.getProvider().getPasswd()); jc.execCommand(ownerNode.getId(), r.getStopResourceCommand(),"ubuntu",n.getPrivateKey());; jc.closeConnection(); } }
graph.addVertex(v); vv.getModel().getGraphLayout().setLocation(v, vv.getRenderContext().getMultiLayerTransformer().inverseTransform(e.getPoint())); Edge newEdge=new Edge(ai.getDestination().getName()+cnt, "destination"); Vertex dest=null; for(Vertex vDest : graph.getVertices()){ if(vDest.getName().equals(ai.getDestination().getName())){ graph.addEdge(newEdge, v, vDest); break;
/** * Execute a given command on an artefact * * @param a the artefact on which the command will be executed * @param command the related shell command as a String * @param user the user associated */ public void executeOnNode(ArtefactInstance a, String command, String user) { Node ownerNode = a.getDestination().getType(); Provider p = ownerNode.getProvider(); JCloudsConnector jc = new JCloudsConnector(p.getName(), p.getLogin(), p.getPasswd()); jc.execCommand(ownerNode.getGroupName(), command, user, ownerNode.getPrivateKey()); 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); } } }
/** * Configuration with parameters IP, IPDest, PortDest * @param r resource for configuration * @param i port of the component to be configured * @param destinationIpAddress IP of the server * @param ipAddress IP of the client * @param destinationPortNumber port of the server * @throws MalformedURLException */ private void configureWithIP(Resource r, ArtefactPortInstance i, String destinationIpAddress, String ipAddress, int destinationPortNumber) { Connector jc; if(r != null){ NodeInstance ownerNode = i.getOwner().getDestination(); Node n=ownerNode.getType(); jc=ConnectorFactory.createConnector(n.getProvider()); //jc=new JCloudsConnector(n.getProvider().getName(), n.getProvider().getLogin(), n.getProvider().getPasswd()); jc.execCommand(ownerNode.getId(), r.getRetrievingResourceCommand(),"ubuntu",n.getPrivateKey()); String configurationCommand=r.getConfigurationResourceCommand()+" \""+ipAddress+"\" \""+destinationIpAddress+"\" "+destinationPortNumber; configureAndStart(jc, n, ownerNode, configurationCommand, ""); jc.closeConnection(); } }
/** * 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(); }
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); } }
if (ai.getDestination() != null) { kai.setDestination(nodeInstances.get(ai.getDestination().getName()));