@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(); }
/** * 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(); }
@Override public boolean equals(Object other) { if (other instanceof Node) { Node otherNode = (Node) other; return name.equals(otherNode.getName()) && cloudProvider.equals(otherNode.getProvider()); } else { return false; } }
net.cloudml.core.Node kNode = factory.createNode(); initProperties(node, kNode, factory); kNode.setName(node.getName()); kNode.setCloudProvider(providers.get(node.getProvider().getName())); kNode.setGroupName(node.getGroupName()); kNode.setImageID(node.getImageId()); kNode.setIs64os(node.getIs64os()); kNode.setLocation(node.getLocation()); kNode.setMinCore(node.getMinCore()); kNode.setMinDisk(node.getMinDisk()); kNode.setMinRam(node.getMinRam()); kNode.setOS(node.getOS()); kNode.setPrivateKey(node.getPrivateKey()); kNode.setSecurityGroup(node.getSecurityGroup()); kNode.setSshKey(node.getSshKey()); kni.setName(ni.getName()); kni.setPublicAddress(ni.getPublicAddress()); kni.setType(nodes.get(ni.getType().getName())); initProperties(ni, kni, factory);
NodeMetadata nodeInstance = null; String groupName="cloudml-instance"; if(!node.getGroupName().equals("")) groupName=node.getGroupName(); if(!node.getImageId().equals("")){ templateBuilder.imageId(node.getImageId()); if (node.getMinRam() > 0) templateBuilder.minRam(node.getMinRam()); if (node.getMinCore() > 0) templateBuilder.minCores(node.getMinCore()); if (!node.getLocation().equals("")) templateBuilder.locationId(node.getLocation()); if (!node.getOS().equals("")) templateBuilder.imageDescriptionMatches(node.getOS()); else templateBuilder.osFamily(OsFamily.UBUNTU); templateBuilder.os64Bit(node.getIs64os()); template.getOptions().as(EC2TemplateOptions.class).mapNewVolumeToDeviceName("/dev/sdm", node.getMinDisk(), true); 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());
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(); } }
Node node = new Node(kNode.getName()); initProperties(kNode, node); node.setProvider(p); node.setGroupName(kNode.getGroupName()); node.setImageId(kNode.getImageID()); node.setIs64os(kNode.getIs64os()); node.setLocation(kNode.getLocation()); node.setMinCore(kNode.getMinCore()); node.setMinDisk(kNode.getMinDisk()); node.setMinRam(kNode.getMinRam()); node.setOS(kNode.getOS()); node.setPrivateKey(kNode.getPrivateKey()); node.setSecurityGroup(kNode.getSecurityGroup()); node.setSshKey(kNode.getSshKey()); nodes.put(node.getName(), node); model.getNodeTypes().put(node.getName(), node);
if (node.getMinCore() > 0 && node.getMinRam() > 0) template.setProductOfferUUID(findProduct(((double)node.getMinRam()), node.getMinCore())); if (!node.getGroupName().equals("")) template.setVdcUUID(findResourceByName(node.getGroupName(),ResourceType.VDC)); if(!node.getImageId().equals("")) template.setImageUUID(findResourceByName(node.getImageId(),ResourceType.IMAGE)); //TODO: find by OS if(!node.getSshKey().equals("")) sshKeyList.add(findResourceByName(node.getSshKey(),ResourceType.SSHKEY));
/** * 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(); }
if(a.getName().equals(nodeType)){ NodeInstance ai= a.instanciates(nodeType+cnt); dm.getNodeInstances().add(ai); Vertex v=new Vertex(nodeType+cnt, "node", ai);
/** * 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()); }
public DefaultListModel fillList(){ DefaultListModel lm=new DefaultListModel(); for(Node n:dmodel.getNodeTypes().values()){ lm.addElement(n.getName()); } for(Artefact n:dmodel.getArtefactTypes().values()){ lm.addElement(n.getName()); } for(Binding b:dmodel.getBindingTypes().values()){ lm.addElement(b.getName()); } return lm; }
/** * 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(); } }
/** * 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); } } }
/** * 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(); } }
/** * 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(); }
/** * 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(); } }
/** * 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(); }
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(); }
/** * 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(); } } }