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 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)); } } }
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));
/** * 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(); }
ClientPortInstance api = new ClientPortInstance(kapi.getName(), clientPorts.get(kapi.getType().getName()), ai); initProperties(kapi, api); ai.getRequired().add(api); clientPortInstances.put(api.getName(), api);
for (ClientPortInstance api : ai.getRequired()) { net.cloudml.core.ClientPortInstance kapi = factory.createClientPortInstance(); kapi.setName(api.getName());