public void restartApp(String appId){ try { BeesClient client = new BeesClient("https://api.cloudbees.com/api", provider.getCredentials().getLogin(), provider.getCredentials().getPassword(), "xml", "1.0"); client.applicationRestart("mod4cloud/" + appId); } catch (Exception e) { journal.log(Level.SEVERE, e.getMessage()); } }
public void bindDbToApp(String appId, String dbId, String alias){ try { //Thread.sleep(60000); BeesClient client = new BeesClient("https://api.cloudbees.com/api", provider.getCredentials().getLogin(), provider.getCredentials().getPassword(), "xml", "1.0"); ServiceResourceBindResponse srbr=client.resourceBind("cb-app", "mod4cloud/"+appId, "cb-db", "mod4cloud/"+dbId, alias, Collections.EMPTY_MAP); Logger.getLogger(Cloud4soaConnector.class.getName()).log(Level.INFO, srbr.getMessage()); restartApp(appId); } catch (Exception ex) { Logger.getLogger(Cloud4soaConnector.class.getName()).log(Level.SEVERE, null, ex); } }
@Override public void configAppParameters(String applicationName, Map<String,String> params) { if("cloudbees".equals(provider.getName().toLowerCase())){ try{ BeesClient client = new BeesClient("https://api.cloudbees.com/api", provider.getCredentials().getLogin(), provider.getCredentials().getPassword(), "xml", "1.0"); client.applicationConfigUpdate(this.credentials.getAccountName()+"/"+applicationName, params); } catch(Exception ex){ Logger.getLogger(Cloud4soaConnector.class.getName()).log(Level.SEVERE, "failed to set up scale", ex); } } }
public Cloud4soaConnector(Provider provider){ this.provider=provider; this.credentials=new Credentials( provider.getCredentials().getLogin(), provider.getCredentials().getPassword(), provider.getProperties().get("account").getValue() ); if(provider.getName().toLowerCase().equals(CLOUDBEES.toLowerCase())) this.platform = CLOUDBEES; if(provider.getName().toLowerCase().equals(RDS.toLowerCase())) this.platform = RDS; }
public static Connector createIaaSConnector(Provider p){ try { if(p.getName().toLowerCase().equals("aws-ec2") || p.getName().toLowerCase().equals("ec2")) return new JCloudsConnector(p.getName(), p.getCredentials().getLogin(), p.getCredentials().getPassword()); if(p.getName().toLowerCase().equals("cloudsigma2-zrh")) return new CloudSigmaConnector(p.getName(), p.getCredentials().getLogin(), p.getCredentials().getPassword()); if(p.getName().toLowerCase().equals("flexiant")) return new FlexiantConnector(p.getProperties().valueOf("endPoint"), p.getCredentials().getLogin(), p.getCredentials().getPassword()); if(p.getName().toLowerCase().equals("openstack-nova")) return new OpenStackConnector(p.getProperties().valueOf("endPoint"), p.getName(), p.getCredentials().getLogin(), p.getCredentials().getPassword()); if(p.getName().toLowerCase().equals("azurecompute")) return new AzureConnector(p.getProperties().valueOf("endPoint"), p.getName(), p.getCredentials().getLogin(), p.getCredentials().getPassword()); } catch (MalformedURLException e) { journal.log(Level.SEVERE, e.getMessage()); } throw new IllegalArgumentException("No such connector"); }
/** * I had a hard-coded region of eu-west-1. Need to fix this some time * @param p * @return */ public static PaaSConnector createPaaSConnector(Provider p){ if("beanstalk".equals(p.getName().toLowerCase()) || "ebs".equals(p.getName().toLowerCase()) || "rds".equals(p.getName().toLowerCase()) || "sqs".equals(p.getName().toLowerCase())) return new BeanstalkConnector(p.getCredentials().getLogin(), p.getCredentials().getPassword(), "eu-west-1"); if("cloudbees".equals(p.getName().toLowerCase())) return new Cloud4soaConnector(p); if("cf".equals(p.getName().toLowerCase()) || p.getName().toLowerCase().contains("cloudfoundry")) return new CloudFoundryConnector(p.getProperties().valueOf("endPoint"),p.getCredentials().getLogin(), p.getCredentials().getPassword(), p.getProperties().valueOf("org"), p.getProperties().valueOf("space")); throw new IllegalArgumentException("No such connector"); } private static PyHrapiConnector loadbalancerConnector = null;
public ComputeMetadata findVMByName(String name, Provider p) {//TODO: use the connector factory JCloudsConnector jc = new JCloudsConnector(p.getName(), p.getCredentials().getLogin(), p.getCredentials().getPassword()); ComputeMetadata cm = jc.getVMByName(name); jc.closeConnection(); return cm; }
public Set<? extends ComputeMetadata> listOfVMs(Provider p) {//TODO: use the connector factory JCloudsConnector jc = new JCloudsConnector(p.getName(), p.getCredentials().getLogin(), p.getCredentials().getPassword()); Set<? extends ComputeMetadata> list = jc.listOfVMs(); jc.closeConnection(); return list; } ////////END OF LEGACY CODE TO BE MIGRATED INTO NEW COMMANDS/////////////////////
public void providersToKmf(List<Provider> providers) { checkNull(providers, "Cannot iterate on null!"); for (Provider p: providers) { net.cloudml.core.Provider kProvider = factory.createProvider(); convertProperties(p, kProvider, factory); kProvider.setName(p.getName()); if (p.getCredentials() instanceof NoCredentials) { // FIXME: Remove this dirty type conditional kProvider.setCredentials("no given credentials"); } else if(p.getCredentials() instanceof MemoryCredentials){ kProvider.setLogin(p.getCredentials().getLogin()); kProvider.setPassword(p.getCredentials().getPassword()); } else { kProvider.setCredentials(((FileCredentials) p.getCredentials()).getPathToCredentials()); } kDeploy.addProviders(kProvider); this.providers.put(kProvider.getName(), kProvider); } }
public String createEnvironmentWithWar(String applicationName, String domainName, String envName, String stackName, int minRam, String warFile, String versionLabel) { String tmp2=""; if(stackName == null || stackName.length()==0){ try { tmp2 = Adapter.uploadAndDeployToEnv(platform, warFile, credentials.getPublicKey(), credentials.getPrivateKey(), credentials.getAccountName(), applicationName, versionLabel, "", "", "", "", "", "deployed by cloudml" ); journal.log(Level.INFO, ">> Created application:" + tmp2); } catch (Cloud4SoaException ex) { Logger.getLogger(Cloud4soaConnector.class.getName()).log(Level.SEVERE, null, ex); } catch (java.lang.NoSuchFieldError ex){ Logger.getLogger(Cloud4soaConnector.class.getName()).log(Level.SEVERE, "The war is deployed, but due to the version conflict of cloudbees, no response is printed"); } } else{ BeesClient client = new BeesClient("https://api.cloudbees.com/api", provider.getCredentials().getLogin(), provider.getCredentials().getPassword(), "xml", "1.0"); Map<String,String> params = new HashMap<String, String>(); params.put("containerType", stackName); try { ApplicationDeployArchiveResponse deployArchiveResponse = client.applicationDeployArchive(this.credentials.getAccountName() + "/" + applicationName, envName, "deployed by cloudml", warFile, warFile, "war", false, params, null); tmp2=deployArchiveResponse.getUrl(); } catch (Exception ex) { Logger.getLogger(Cloud4soaConnector.class.getName()).log(Level.SEVERE, null, ex); } } return tmp2; }
/** * Create the VM described by the given VMInstance object * * @param a */ public void createVM(VMInstance a) { Provider provider = a.getType().getProvider(); JCloudsConnector jc = new JCloudsConnector(provider.getName(), provider.getCredentials().getLogin(), provider.getCredentials().getPassword()); jc.createInstance(a); jc.closeConnection(); }
Deployment temp=(Deployment)jc.load(is); for(Provider p: temp.getProviders()){ if(p.getCredentials() instanceof FileCredentials){ String login = ""; String password = ""; if(p.getCredentials().getLogin() != null) login=p.getCredentials().getLogin(); if(p.getCredentials().getPassword() != null) password=p.getCredentials().getPassword(); MemoryCredentials mc=new MemoryCredentials(login, password); p.setCredentials(mc);
/** * Configure a component * * @param jc a connector * @param n A VM type * @param ni a VM instance * @param configurationCommand the command to configure the component, * parameters are: IP IPDest portDest */ protected void configure(Connector jc, VM n, VMInstance ni, String configurationCommand, Boolean keyRequired) { if (!configurationCommand.equals("")) { if(keyRequired) jc.execCommand(ni.getId(), configurationCommand+" "+ni.getType().getProvider().getCredentials().getLogin()+" "+ni.getType().getProvider().getCredentials().getPassword(), "ubuntu", n.getPrivateKey()); else executeCommand(ni, jc, configurationCommand); } }
private void executeInstallCommand(InternalComponentInstance x, VMInstance owner, Connector jc) { unlessNotNull("Cannot install with an argument at null", x, owner, jc); for (Resource r : x.getType().getResources()) { if (!r.getInstallCommand().equals("")) { if (r.getRequireCredentials()) { jc.execCommand(owner.getId(), CloudMLQueryUtil.cloudmlStringRecover(r.getInstallCommand(), r, x) + " " + owner.getType().getProvider().getCredentials().getLogin() + " " + owner.getType().getProvider().getCredentials().getPassword(), "ubuntu", owner.getType().getPrivateKey()); } else { executeCommand(owner, jc, CloudMLQueryUtil.cloudmlStringRecover(r.getInstallCommand(), r, x)); } } } }
@Override public void handle(Destroy command) { if (isDeploymentLoaded()) { final VMInstance instance = deploy.getComponentInstances().onlyVMs().firstNamed(command.getInstanceId()); if (instance == null) { final String text = String.format("No VM 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.getCredentials().getLogin(), p.getCredentials().getPassword()); jc.destroyVM(instance.getId()); dispatch(new Message(command, Category.INFORMATION, "VM instance terminated")); } } else { reportNoDeploymentLoaded(command); } }
/** * Retrieve the resources associated to an InternalComponent * * @param x the internalComponent we want to retrieve the resource * @param owner the externalComponent on which the resources will be * downloaded * @param jc the connector used to trigger the commands */ private void executeRetrieveCommand(InternalComponentInstance x, VMInstance owner, Connector jc) { unlessNotNull("Cannot retrieve resources of null!", x, owner, jc); for (Resource r : x.getType().getResources()) { if (!r.getRetrieveCommand().equals("")) { if (r.getRequireCredentials()) jc.execCommand(owner.getId(), CloudMLQueryUtil.cloudmlStringRecover(r.getRetrieveCommand(), r, x) + " " + owner.getType().getProvider().getCredentials().getLogin() + "" + owner.getType().getProvider().getCredentials().getPassword(), "ubuntu", owner.getType().getPrivateKey()); else executeCommand(owner, jc, CloudMLQueryUtil.cloudmlStringRecover(r.getRetrieveCommand(), r, x)); } } }
@Override public void handle(Upload command) { if (isDeploymentLoaded()) { ExternalComponentInstance ownerVM = null; for (ExternalComponentInstance ni: deploy.getComponentInstances().onlyExternals()) { if (ni.getName().equals(command.getArtifactId())) { ownerVM = ni; } } if (ownerVM != null && ownerVM instanceof VMInstance) { Provider p = ((VMInstance) ownerVM).getType().getProvider(); JCloudsConnector jc = new JCloudsConnector(p.getName(), p.getCredentials().getLogin(), p.getCredentials().getPassword()); ComputeMetadata c = jc.getVMByName(command.getArtifactId()); jc.uploadFile(command.getLocalPath(), command.getRemotePath(), c.getId(), "ubuntu", ((VM) ownerVM.getType()).getPrivateKey()); } else { final String text = "There is no VM with this ID!"; final Message message = new Message(command, Category.ERROR, text); dispatch(message); } } else { reportNoDeploymentLoaded(command); } }
/** * Execute a given command on an component * * @param a the component on which the command will be executed * @param command the related shell command as a String * @param user the user associated */ public void executeOnVM(ComponentInstance a, String command, String user) {//TODO: use the connector factory VM ownerVM = (VM) deployer.getDestination(a).getType();//TODO: generics Provider provider = ownerVM.getProvider(); final Credentials credentials = provider.getCredentials(); JCloudsConnector jc = new JCloudsConnector(provider.getName(), credentials.getLogin(), credentials.getPassword()); jc.execCommand(ownerVM.getGroupName(), command, user, ownerVM.getPrivateKey()); jc.closeConnection(); }
initProperties(p, kProvider, factory); kProvider.setName(p.getName()); kProvider.setCredentials(p.getCredentials()); kDeploy.addProviders(kProvider);