@Override public boolean equals(Object other) { if (other instanceof NodeInstance) { NodeInstance otherNode = (NodeInstance) other; return name.equals(otherNode.getName()) && type.equals(otherNode.getType()); } else { return false; } } }
public CPIMTable(Vertex v){ super(); this.v=v; Class c; if(v.getType().equals("node")) c=((NodeInstance)v.getInstance()).getType().getClass(); else c=((ArtefactInstance)v.getInstance()).getType().getClass(); this.properties=c.getDeclaredFields(); }
public Object getValueAt(int rowIndex, int columnIndex) { Object o=null; switch(columnIndex){ case 0: return properties[rowIndex].getName(); default: try { properties[rowIndex].setAccessible(true); if(v.getType().equals("node")) o=properties[rowIndex].get(((NodeInstance)v.getInstance()).getType()); else o=properties[rowIndex].get(((ArtefactInstance)v.getInstance()).getType()); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } return o+""; } }
/** * Provision a node * @param n a NodeInstance */ private void provisionANode(NodeInstance n){ Provider p=n.getType().getProvider(); Connector jc=ConnectorFactory.createConnector(p); jc.createInstance(n); jc.closeConnection(); }
/** * To initialize a deployment Model as the model of the current system if the system is already running * @param current the current Deployment model */ public void setCurrentModel(DeploymentModel current){ this.currentModel=current; Connector jc; for(NodeInstance n: currentModel.getNodeInstances()){ if(n.getPublicAddress().equals("")){ jc=ConnectorFactory.createConnector(n.getType().getProvider()); jc.updateNodeMetadata(n); } } }
/** * Terminate a node * @param n A node instance to be terminated * @throws MalformedURLException */ private void terminateNode(NodeInstance n){ Provider p=n.getType().getProvider(); Connector jc=ConnectorFactory.createConnector(p); jc.destroyNode(n.getId()); jc.closeConnection(); }
/** * Create the node described by the given NodeInstance object * * @param a */ public void createNode(NodeInstance a) { Provider p = a.getType().getProvider(); JCloudsConnector jc = new JCloudsConnector(p.getName(), p.getLogin(), p.getPasswd()); jc.createInstance(a); jc.closeConnection(); }
/** * 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(); } } }
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 void handle(Upload command) { if (deploy == null) { final String text = "No deployment model. Please first load a deployment model"; final Message message = new Message(command, Category.ERROR, text); dispatch(message); } else { NodeInstance ownerNode=null; for(NodeInstance ni : deploy.getNodeInstances()){ if(ni.getName().equals(command.getArtifactId())) ownerNode=ni; } if(ownerNode != null){ Provider p = ownerNode.getType().getProvider(); JCloudsConnector jc = new JCloudsConnector(p.getName(), p.getLogin(), p.getPasswd()); ComputeMetadata c = jc.getNodeByName(command.getArtifactId()); jc.uploadFile(command.getLocalPath(), command.getRemotePath(), c.getId(), "ubuntu", ownerNode.getType().getPrivateKey()); }else{ final String text = "There is no node with this ID!"; final Message message = new Message(command, Category.ERROR, text); dispatch(message); } } //command.markAsCompleted(); }
Server template = new Server(); if(findResourceByName(a.getName(), ResourceType.SERVER).equals("")){ Node node= a.getType(); List<String> sshKeyList = new ArrayList<String> ();
/** * Stop a specific artefact instance * @param a An Artefact Instance * @throws MalformedURLException */ private void stopArtefact(ArtefactInstance a) { NodeInstance ownerNode = findDestination(a); if(ownerNode != null){ Node n=ownerNode.getType(); Connector jc=ConnectorFactory.createConnector(n.getProvider()); String stopCommand=a.getType().getResource().getStopResourceCommand(); jc.execCommand(ownerNode.getId(), stopCommand,"ubuntu",n.getPrivateKey()); jc.closeConnection(); } }
/** * 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(); }
/** * 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 handle(Destroy command) { if (deploy == null) { final String text = "No deployment model. Please first load a deployment model"; final Message message = new Message(command, Category.ERROR, text); dispatch(message); } else { final NodeInstance instance = findNodeInstanceById(command.getInstanceId()); if (instance == null) { final String text = String.format("No node with ID=\"%s\"", command.getInstanceId()); final Message message = new Message(command, Category.ERROR, text); dispatch(message); } else { Provider p = instance.getType().getProvider(); JCloudsConnector jc = new JCloudsConnector(p.getName(), p.getLogin(), p.getPasswd()); jc.destroyNode(instance.getId()); dispatch(new Message(command, Category.INFORMATION, "Node instance terminated")); } } //command.markAsCompleted(); }
/** * 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(); } }
Node node= a.getType(); ComputeMetadata cm= getNodeByName(a.getName());
/** * 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(); }
kni.setName(ni.getName()); kni.setPublicAddress(ni.getPublicAddress()); kni.setType(nodes.get(ni.getType().getName())); initProperties(ni, kni, factory);