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 ""; }
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); } }
/** * 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; } }
/** * 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); } } }
net.cloudml.core.ClientPortInstance kapi = factory.createClientPortInstance(); kapi.setName(api.getName()); kapi.setType(clientPorts.get(api.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); } }