@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; } }
public ArtefactInstance instanciates(String name) { return new ArtefactInstance(name, this); }
@Override public boolean equals(Object other) { if (other instanceof ServerPortInstance) { ServerPortInstance otherNode = (ServerPortInstance) other; return name.equals(otherNode.getName()) && owner.equals(otherNode.getOwner()); } else { return false; } }
kai.setName(ai.getName()); kai.setType(artefacts.get(ai.getType().getName())); initProperties(ai, kai, factory); if (ai.getDestination() != null) { kai.setDestination(nodeInstances.get(ai.getDestination().getName())); for (ServerPortInstance api : ai.getProvided()) { net.cloudml.core.ServerPortInstance kapi = factory.createServerPortInstance(); kapi.setName(api.getName()); for (ClientPortInstance api : ai.getRequired()) { net.cloudml.core.ClientPortInstance kapi = factory.createClientPortInstance(); kapi.setName(api.getName());
ArtefactInstance ai = new ArtefactInstance(kai.getName(), artefacts.get(kai.getType().getName())); initProperties(kai, ai); artefactInstances.put(ai.getName(), ai); ai.setDestination(nodeInstances.get(kai.getDestination().getName())); ServerPortInstance api = new ServerPortInstance(kapi.getName(), serverPorts.get(kapi.getType().getName()), ai); initProperties(kapi, api); ai.getProvided().add(api); serverPortInstances.put(api.getName(), api); ClientPortInstance api = new ClientPortInstance(kapi.getName(), clientPorts.get(kapi.getType().getName()), ai); initProperties(kapi, api); ai.getRequired().add(api); clientPortInstances.put(api.getName(), api);
if(a.getName().equals(nodeType)){ ArtefactInstance ai= a.instanciates(nodeType+cnt); ai.setDestination(selectDestination()); dm.getArtefactInstances().add(ai); for(ClientPort c:a.getRequired()) ai.getRequired().add(new ClientPortInstance(c.getName()+cnt, c, ai)); for(ServerPort s:a.getProvided()) ai.getProvided().add(new ServerPortInstance(s.getName()+cnt, s, ai)); Vertex v=new Vertex(nodeType+cnt, "soft", ai); 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;
/** * 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(); }
/** * 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; } }
/** * 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(); } } }
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; }
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(); } }
public String selectServerPortInstance(BindingInstance bi){ JPanel panel = new JPanel(); panel.add(new JLabel("Please make a selection:")); DefaultComboBoxModel model = new DefaultComboBoxModel(); for(ArtefactInstance ai:dm.getArtefactInstances()){ for(ServerPortInstance ci:ai.getProvided()){ if(ci.getType().equals(bi.getType().getServer())){ model.addElement(ci); } } } JComboBox comboBox = new JComboBox(model); panel.add(comboBox); int result = JOptionPane.showConfirmDialog(null, panel, "ServerPort", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); switch (result) { case JOptionPane.OK_OPTION: bi.setServer((ServerPortInstance)comboBox.getSelectedItem()); return ((ServerPortInstance)comboBox.getSelectedItem()).getOwner().getName(); } return ""; }
public String selectClientPortInstance(BindingInstance bi){ JPanel panel = new JPanel(); panel.add(new JLabel("Please make a selection:")); DefaultComboBoxModel model = new DefaultComboBoxModel(); for(ArtefactInstance ai:dm.getArtefactInstances()){ System.out.println(ai.getRequired()); for(ClientPortInstance ci:ai.getRequired()){ System.out.println(bi.getType().getClient() + " #### "+ ci.getType()); if(ci.getType().equals(bi.getType().getClient())){ model.addElement(ci); } } } JComboBox comboBox = new JComboBox(model); panel.add(comboBox); int result = JOptionPane.showConfirmDialog(null, panel, "ClientPort", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); switch (result) { case JOptionPane.OK_OPTION: bi.setClient((ClientPortInstance)comboBox.getSelectedItem()); return ((ClientPortInstance)comboBox.getSelectedItem()).getOwner().getName(); } return ""; }
@Override public String toString() { return "ArtefactPortInstance " + name + " owner:" + owner.getName(); } }
@Override public String toString() { return "Instance " + name + " : " + getType().getName(); }
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)); } } }
/** * 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(); } }
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); } }
/** * 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); } } }
@Override public String toString() { return "ClientPortInstance " + name + " owner:" + owner.getName(); }