@Override public String toString() { return "ClientTypePort " + name + " ownerType" + owner.getName(); } }
Artefact a = new Artefact(ka.getName()); initProperties(ka, a); artefacts.put(a.getName(), a); initProperties(kap, ap); ap.setPortNumber(kap.getPortNumber()); a.getProvided().add(ap);//! initProperties(kap, ap); ap.setPortNumber(kap.getPortNumber()); a.getRequired().add(ap);//! a.setResource(r); model.getArtefactTypes().put(a.getName(), a); Artefact a = artefacts.get(ka.getName()); if (ka.getDestination() != null) { a.setDestination(serverPorts.get(ka.getDestination().getName()));
ka.setName(a.getName()); initProperties(a, ka, factory); for (ServerPort ap : a.getProvided()) {//TODO: duplicated code to be rationalized net.cloudml.core.ServerPort kap = factory.createServerPort(); kap.setName(ap.getName()); for (ClientPort ap : a.getRequired()) { net.cloudml.core.ClientPort kap = factory.createClientPort(); kap.setName(ap.getName()); kr.setName(a.getResource().getName()); kr.setDeployingCommand(a.getResource().getDeployingResourceCommand()); kr.setRetrievingCommand(a.getResource().getRetrievingResourceCommand()); kr.setConfigurationCommand(a.getResource().getConfigurationResourceCommand()); kr.setStartCommand(a.getResource().getStartResourceCommand()); kr.setStopCommand(a.getResource().getStopResourceCommand()); for(Entry<String, String> up : a.getResource().getUploadCommand().entrySet()){ net.cloudml.core.UploadCommand kup = factory.createUploadCommand(); kup.setSource(up.getKey()); net.cloudml.core.Artefact ka = artefacts.get(a.getName()); if (a.getDestination() != null) { ka.setDestination(serverPorts.get(a.getDestination().getName())); net.cloudml.core.ArtefactInstance kai = factory.createArtefactInstance(); kai.setName(ai.getName()); kai.setType(artefacts.get(ai.getType().getName()));
if(a.getName().equals(nodeType)){ ArtefactInstance ai= a.instanciates(nodeType+cnt); ai.setDestination(selectDestination()); 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)); Vertex v=new Vertex(nodeType+cnt, "soft", ai);
/** * 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(); } } }
@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; } }
/** * 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(); } }
@Override public String toString() { return "ArtefactPortType " + name + " ownerType" + owner.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(); }
@Override public String toString() { return "ServerPortType " + name + " ownerType" + owner.getName(); }
/** * 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(); } }
@Override public boolean equals(Object other) { if (other instanceof Artefact) { Artefact otherArt = (Artefact) other; return name.equals(otherArt.getName()); } else { return false; } }
@Override public String toString() { return "Instance " + name + " : " + getType().getName(); }
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; }