@SuppressWarnings("unchecked") private ApplicationStats doGetApplicationStats(UUID appId, CloudApplication.AppState appState) { List<InstanceStats> instanceList = new ArrayList<InstanceStats>(); if (appState.equals(CloudApplication.AppState.STARTED)) { Map<String, Object> respMap = getInstanceInfoForApp(appId, "stats"); if (!CollectionUtils.isEmpty(respMap)) { for (String instanceId : respMap.keySet()) { InstanceStats instanceStats = new InstanceStats(instanceId, (Map<String, Object>) respMap.get(instanceId)); instanceList.add(instanceStats); } } } return new ApplicationStats(instanceList); }
state = AppState.valueOf((String) attributes.get("state")); if (attributes.containsKey("memory")) { memory = (Integer) attributes.get("memory");
app.setInstances(getAttributeOfV2Resource(resource, "instances", Integer.class)); app.setServices(new ArrayList<String>()); app.setState(CloudApplication.AppState.valueOf(getAttributeOfV2Resource(resource, "state", String.class)));
state = AppState.valueOf((String) attributes.get("state")); if (attributes.containsKey("memory")) { memory = (Integer) attributes.get("memory");
app.setInstances(getEntityAttribute(resource, "instances", Integer.class)); app.setServices(new ArrayList<String>()); app.setState(CloudApplication.AppState.valueOf(getEntityAttribute(resource, "state", String.class)));
@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; } }
@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 boolean isStarted(CloudControllerClient client, String appName) { try { CloudApplication app = client.getApplication(appName); return app.getState() .equals(AppState.STARTED); } catch (CloudOperationException e) { if (e.getStatusCode() .equals(HttpStatus.INTERNAL_SERVER_ERROR)) { logger.warn(e.getMessage(), e); return false; } throw e; } }
@SuppressWarnings("unchecked") private CloudApplication mapCloudApplication(Map<String, Object> resource) { UUID appId = resourceMapper.getGuidOfV2Resource(resource); CloudApplication cloudApp = null; if (resource != null) { int running = getRunningInstances(appId, CloudApplication.AppState.valueOf(CloudEntityResourceMapper.getAttributeOfV2Resource(resource, "state", String.class))); ((Map<String, Object>) resource.get("entity")).put("running_instances", running); cloudApp = resourceMapper.mapResource(resource, CloudApplication.class); cloudApp.setUris(findApplicationUris(cloudApp.getMeta() .getGuid())); } return cloudApp; }
private boolean isStopped(CloudApplication app) { return app.getRunningInstances() == 0 && getRequestedState(app).equals(org.cloudfoundry.client.lib.domain.CloudApplication.AppState.STOPPED); }
private boolean isStarted(CloudApplication app) { return app.getRunningInstances() == app.getInstances() && app.getInstances() != 0 && getRequestedState(app).equals(org.cloudfoundry.client.lib.domain.CloudApplication.AppState.STARTED); }
private boolean isStarted(CloudControllerClient client, String appName) { try { CloudApplication app = client.getApplication(appName); return app.getState() .equals(AppState.STARTED); } catch (CloudOperationException e) { if (e.getStatusCode() .equals(HttpStatus.INTERNAL_SERVER_ERROR)) { logger.warn(e.getMessage(), e); return false; } throw e; } }
@SuppressWarnings("unchecked") private CloudApplication mapCloudApplication(Map<String, Object> resource) { UUID appId = resourceMapper.getGuidOfResource(resource); CloudApplication cloudApp = null; if (resource != null) { int running = getRunningInstances(appId, CloudApplication.AppState.valueOf( CloudEntityResourceMapper.getEntityAttribute(resource, "state", String.class))); ((Map<String, Object>)resource.get("entity")).put("running_instances", running); cloudApp = resourceMapper.mapResource(resource, CloudApplication.class); cloudApp.setUris(findApplicationUris(cloudApp.getMeta().getGuid())); } return cloudApp; }
@Override public InstancesInfo getApplicationInstances(CloudApplication app) { if (app.getState().equals(CloudApplication.AppState.STARTED)) { return doGetApplicationInstances(app.getMeta().getGuid()); } return null; }
@SuppressWarnings("unchecked") private ApplicationStats doGetApplicationStats(UUID appId, CloudApplication.AppState appState) { List<InstanceStats> instanceList = new ArrayList<InstanceStats>(); if (appState.equals(CloudApplication.AppState.STARTED)) { Map<String, Object> respMap = getInstanceInfoForApp(appId, "stats"); for (String instanceId : respMap.keySet()) { InstanceStats instanceStats = new InstanceStats(instanceId, (Map<String, Object>) respMap.get(instanceId)); instanceList.add(instanceStats); } } return new ApplicationStats(instanceList); }
private boolean isApplicationReady(CloudApplication application) { /* * RestTemplate restTemplate = new RestTemplate(); String response = * restTemplate.getForObject(application.getUris().get(0), * String.class); if * (response.contains("B29 ROUTER: 404 - FILE NOT FOUND")) { return * false; } */ return AppState.STARTED.equals(application.getState()); }
@Override public InstancesInfo getApplicationInstances(CloudApplication app) { if (app.getState() .equals(CloudApplication.AppState.STARTED)) { return doGetApplicationInstances(app.getMeta() .getGuid()); } return null; }