private boolean unbindNotRequiredServices(CloudApplication app, List<String> requiredServices, CloudControllerClient client) { boolean hasUnbindedService = false; for (String serviceName : app.getServices()) { if (!requiredServices.contains(serviceName)) { unbindService(app.getName(), serviceName, client); hasUnbindedService = true; } } return hasUnbindedService; }
private boolean isStarted(CloudApplication app) { return app.getRunningInstances() == app.getInstances() && app.getInstances() != 0 && getRequestedState(app).equals(org.cloudfoundry.client.lib.domain.CloudApplication.AppState.STARTED); }
String deploymentName = cloudApplication.getName(); ApplicationDeploymentInfo deploymentInfo = new ApplicationDeploymentInfo(deploymentName); deploymentInfo.setInstances(cloudApplication.getInstances()); deploymentInfo.setStaging(cloudApplication.getStaging()); deploymentInfo.setMemory(cloudApplication.getMemory()); List<String> boundServiceNames = cloudApplication.getServices(); if (boundServiceNames != null) { List<CloudService> services = new ArrayList<CloudService>(); if (cloudApplication.getUris() != null) { deploymentInfo.setUris(new ArrayList<String>(cloudApplication.getUris())); Map<String, String> envMap = cloudApplication.getEnvAsMap();
@SuppressWarnings({ "unchecked", "rawtypes" }) private CloudApplication mapApplicationResource(Map<String, Object> resource) { CloudApplication app = new CloudApplication( getMeta(resource), getNameOfResource(resource)); app.setInstances(getEntityAttribute(resource, "instances", Integer.class)); app.setServices(new ArrayList<String>()); app.setState(CloudApplication.AppState.valueOf(getEntityAttribute(resource, "state", String.class))); app.setDebug(null); app.setRunningInstances(runningInstancesAttribute); Integer healthCheckTimeout = getEntityAttribute(resource, "health_check_timeout", Integer.class); Staging staging = new Staging(command, buildpack, stack.getName(), healthCheckTimeout, detectedBuildpack); app.setStaging(staging); app.setSpace(space); app.setEnv(envMap); app.setMemory(getEntityAttribute(resource, "memory", Integer.class)); app.setDiskQuota(getEntityAttribute(resource, "disk_quota", Integer.class)); List<Map<String, Object>> serviceBindings = getEntityAttribute(resource, "service_bindings", List.class); List<String> serviceList = new ArrayList<String>(); app.setServices(serviceList); return app;
private Map<String, CloudApplication> createExistingApplicationsMap(List<CloudApplication> existingApps) { Map<String, CloudApplication> applicationsMap = new HashMap<>(existingApps.size()); existingApps.forEach(app -> applicationsMap.put(app.getName(), app)); return applicationsMap; }
@Override public void exec() { List<MonitoredVm> list = new ArrayList<MonitoredVm>(); //Get all servers List<CloudApplication> cloudFoundryApps; cloudFoundryApps = connector.listApplications(); if (cloudFoundryApps != null) { for (CloudApplication o : cloudFoundryApps) { MonitoredVm temp = new MonitoredVm(o.getUris().get(0), o.getName(), toState(o.getState())); list.add(temp); } } ListManager.listManager(list, VMs, coord); }
if (hasChanged(staging, existingApp.getStaging())) { getStepLogger().debug("Updating staging of application \"{0}\"", appName); client.updateApplicationStaging(appName, staging); appPropertiesChanged = true; if (memory != null && !memory.equals(existingApp.getMemory())) { getStepLogger().debug("Updating memory of application \"{0}\"", appName); client.updateApplicationMemory(appName, memory); appPropertiesChanged = true; if (diskQuota != null && !diskQuota.equals(existingApp.getDiskQuota())) { getStepLogger().debug("Updating disk quota of application \"{0}\"", appName); client.updateApplicationDiskQuota(appName, diskQuota); appPropertiesChanged = true; if (hasChanged(uris, existingApp.getUris())) { getStepLogger().debug("Updating uris of application \"{0}\" with uri: {1}", appName, uris); client.updateApplicationUris(appName, uris); updateAppDigest(env, existingApp.getEnvAsMap()); if (!env.equals(existingApp.getEnvAsMap())) { getStepLogger().debug("Updating env of application \"{0}\"", appName); getStepLogger().debug("Updated env: {0}", JsonUtil.toJson(env, true));
String appName = app.getName(); Date createdOn = app.getMeta() .getCreated(); Date updatedOn = app.getMeta() .getUpdated(); DeployedMtaModule module = new DeployedMtaModule(moduleName, appName, createdOn, updatedOn, appServices, providedDependencies, app.getUris()); modules.add(module); modulesMap.put(mtaMetadata, modules);
journal.log(Level.INFO, ">> Environment created ... "); CloudApplication app = connectedClient.getApplication(applicationName); journal.log(Level.INFO, ">> Application details: "+ app.getName() + ", URI: " + app.getUris().get(0)+ ", Memory: " +app.getMemory()); try { journal.log(Level.INFO, ">> Uploading application ... "); connectedClient.uploadApplication(applicationName,new File(warFile), null); journal.log(Level.INFO, ">> Starting application ... "); connectedClient.startApplication(app.getName()); } catch (IOException e) { journal.log(Level.SEVERE, e.getMessage());
private static ApplicationMtaMetadata attemptToParseAppMetadata(CloudApplication app) { Map<String, String> appEnv = app.getEnvAsMap(); DeployedMtaMetadata mtaMetadata = parseMtaMetadata(app, appEnv); List<String> services = parseServices(appEnv); String moduleName = parseModuleName(app, appEnv); List<String> providedDependencyNames = parseProvidedDependencyNames(app.getName(), appEnv); List<Object> metadataFields = Arrays.asList(mtaMetadata, services, moduleName, providedDependencyNames); if (metadataFields.stream() .allMatch(Objects::isNull)) { return null; } if (metadataFields.stream() .anyMatch(Objects::isNull)) { throw new ParsingException(Messages.MTA_METADATA_FOR_APP_0_IS_INCOMPLETE, app.getName()); } return new ApplicationMtaMetadata(mtaMetadata, services, moduleName, providedDependencyNames); }
@Override public void updateApplicationUris(String appName, List<String> uris) { CloudApplication app = getApplication(appName); List<String> newUris = new ArrayList<String>(uris); newUris.removeAll(app.getUris()); List<String> removeUris = app.getUris(); removeUris.removeAll(uris); removeUris(removeUris, app.getMeta().getGuid()); addUris(newUris, app.getMeta().getGuid()); }
@Override protected StepPhase executeStep(ExecutionWrapper execution) { // Get the next cloud application from the context CloudApplication app = StepsUtil.getApp(execution.getContext()); // Get the existing application from the context CloudApplication existingApp = StepsUtil.getExistingApp(execution.getContext()); try { if (existingApp != null && !existingApp.getState() .equals(AppState.STOPPED)) { getStepLogger().info(Messages.STOPPING_APP, app.getName()); // Get a cloud foundry client CloudControllerClient client = execution.getControllerClient(); // Stop the application client.stopApplication(app.getName()); getStepLogger().debug(Messages.APP_STOPPED, app.getName()); } else { getStepLogger().debug("Application \"{0}\" already stopped", app.getName()); } return StepPhase.DONE; } catch (CloudOperationException coe) { CloudControllerException e = new CloudControllerException(coe); getStepLogger().error(e, Messages.ERROR_STOPPING_APP, app.getName()); throw e; } catch (SLException e) { getStepLogger().error(e, Messages.ERROR_STOPPING_APP, app.getName()); throw e; } }
private List<String> getApplicationUris(CloudApplication application) { List<String> uris = application.getUris(); if (uris == null) { return Collections.emptyList(); } return uris; }
private static boolean hasGuid(CloudApplication app, UUID appGuid) { return app.getMeta() .getGuid() .equals(appGuid); }
@Override protected StepPhase executeStep(ExecutionWrapper execution) { CloudApplication app = StepsUtil.getApp(execution.getContext()); CloudApplication existingApp = StepsUtil.getExistingApp(execution.getContext()); try { getStepLogger().debug(Messages.SCALING_APP, app.getName()); CloudControllerClient client = execution.getControllerClient(); String appName = app.getName(); Integer instances = (app.getInstances() != 0) ? app.getInstances() : null; if (instances != null && (existingApp == null || !instances.equals(existingApp.getInstances()))) { getStepLogger().info(Messages.SCALING_APP_0_TO_X_INSTANCES, appName, instances); client.updateApplicationInstances(appName, instances); } getStepLogger().debug(Messages.APP_SCALED, app.getName()); return StepPhase.DONE; } catch (CloudOperationException coe) { CloudControllerException e = new CloudControllerException(coe); getStepLogger().error(e, Messages.ERROR_SCALING_APP, app.getName()); throw e; } catch (SLException e) { getStepLogger().error(e, Messages.ERROR_SCALING_APP, app.getName()); throw e; } }
private CloudApplication createCloudApplication(Map<Object, Object> appEnv) { CloudApplication app = new CloudApplication(null, null); app.setEnv(appEnv); return app; } }
private org.cloudfoundry.client.lib.domain.CloudApplication.AppState getRequestedState(CloudApplication app) { return app.getState(); }
if (!app.getServices() .contains(serviceName)) { CloudService cloudService = getService(serviceName); for (String serviceName : app.getServices()) { if (!services.contains(serviceName)) { CloudService cloudService = getService(serviceName, false); doBindService(app.getMeta() .getGuid(), serviceId); doUnbindService(app.getMeta() .getGuid(), serviceId);