/** * 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); } } }
public NodeInstance instanciates() { return new NodeInstance("", this); } }
public void updateNodeMetadata(NodeInstance a) { a.setId(findResourceByName(a.getName(), ResourceType.SERVER)); Server temp=(Server)findObjectResourceByName(a.getName(), ResourceType.SERVER); a.setPublicAddress(temp.getNics().get(0).getIpAddresses().get(0).getIpAddress()); }
public void createInstance(NodeInstance a){ try { Server template = new Server(); if(findResourceByName(a.getName(), ResourceType.SERVER).equals("")){ Node node= a.getType(); List<String> sshKeyList = new ArrayList<String> (); sshKeyList.add(findResourceByName(node.getSshKey(),ResourceType.SSHKEY)); template.setResourceName(a.getName()); Nic n=new Nic(); n.setNetworkUUID("89b1a8d2-42dc-3c0a-b5f1-c9f4fc5aacc8"); //TODO: to be added in the metamodel service.waitForJob(job.getResourceUUID(), false); a.getProperties().add(new Property("ProviderInstanceType",template.getProductOfferName())); a.setId(findResourceByName(a.getName(), ResourceType.SERVER)); Job startJob=service.changeServerStatus(a.getId(), ServerStatus.RUNNING, true, null, null); service.waitForJob(startJob.getResourceUUID(), false); Thread.sleep(90000); a.setId(findResourceByName(a.getName(), ResourceType.SERVER)); Server temp=(Server)findObjectResourceByName(a.getName(), ResourceType.SERVER); a.setPublicAddress(temp.getNics().get(0).getIpAddresses().get(0).getIpAddress()); journal.log(Level.INFO, ">> Running node: " + a.getName() + " id: " + a.getId() + " with public address: " + a.getPublicAddress()); } catch (ExtilityException e) {
Node node= a.getType(); ComputeMetadata cm= getNodeByName(a.getName()); a.getProperties().add(new Property("ProviderInstanceType", template.getHardware().getId())); a.getProperties().add(new Property("location", template.getLocation().getId())); template.getOptions().as(EC2TemplateOptions.class).securityGroups(node.getSecurityGroup()); template.getOptions().as(EC2TemplateOptions.class).keyPair(node.getSshKey()); template.getOptions().as(EC2TemplateOptions.class).userMetadata("Name", a.getName()); template.getOptions().as(EC2TemplateOptions.class).overrideLoginUser(a.getName()); a.setPublicAddress(nodeInstance.getPublicAddresses().iterator().next()); a.setId(nodeInstance.getId());
kni.setName(ni.getName()); kni.setPublicAddress(ni.getPublicAddress()); kni.setType(nodes.get(ni.getType().getName())); initProperties(ni, kni, factory); kai.setDestination(nodeInstances.get(ai.getDestination().getName()));
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(); }
/** * Search for a node instance whose name matches a given id * * @param id of the Node instance * @return the node instance with the given id or null */ private NodeInstance findNodeInstanceById(final String id) { for (NodeInstance ni : deploy.getNodeInstances()) { if (ni.getName().equals(id)) { return ni; } } return null; }
NodeInstance ni = new NodeInstance(kni.getName(), nodes.get(kni.getType().getName())); ni.setPublicAddress(kni.getPublicAddress()); initProperties(kni, ni); nodeInstances.put(ni.getName(), ni);
public void execCommand(NodeInstance n, String command, String login, String keyPath){ SSHConnector sc=new SSHConnector(keyPath, login, n.getPublicAddress()); sc.execCommandSsh(command); }
/** * Compares the nodes between the targeted and the current deployment model */ public void compareNodes(){ journal.log(Level.INFO, ">> Comparing nodes ..."); Boolean match=false; for(NodeInstance ni : currentDM.getNodeInstances()){ secondloop:{ for(NodeInstance ni2 : targetDM.getNodeInstances()){ match=ni.equals(ni2); if(ni.equals(ni2)){ matchingNodes.put(ni, ni2); break secondloop; } }} if(!match){ removeNode(ni); } } //add the rest addNodes(); }
/** * Configure and start an artefact * @param jc a connector * @param n A node type * @param ni a node instance * @param configurationCommand the command to configure the artefact, parameters are: IP IPDest portDest * @param startCommand the command to start the artefact */ private void configureAndStart(Connector jc, Node n, NodeInstance ni, String configurationCommand, String startCommand){ if(!configurationCommand.equals("")) jc.execCommand(ni.getId(), configurationCommand,"ubuntu",n.getPrivateKey()); if(!startCommand.equals("")) jc.execCommand(ni.getId(), startCommand,"ubuntu",n.getPrivateKey()); }
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 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+""; } }
/** * Update the runtime metadata of a node if already deployed * @param a description of a node */ public void updateNodeMetadata(NodeInstance a){ ComputeMetadata cm= getNodeByName(a.getName()); if(cm != null){ a.setPublicAddress(getNodeById(cm.getId()).getPublicAddresses().iterator().next()); a.setId(cm.getId()); } }
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; }
@Override public String toString() { return "NodeInstance: "+name+" Type:"+type.getName()+"{\n" + "minRam:" + type.getMinRam()+"\n"+ "minCore" + type.getMinCore()+"\n"+ "minDisk" + type.getMinDisk()+"\n"+ "OS" + type.getOS()+"\n"+ "location" + type.getLocation()+"\n"+ "publicAdress" + getPublicAddress()+"\n"+ "groupName" + type.getGroupName(); }
@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; } }