private org.cloudfoundry.client.lib.domain.CloudApplication.AppState getRequestedState(CloudApplication app) { return app.getState(); }
/** * * @return {@link IServer} state */ public synchronized int getState() { if (application != null) { AppState state = application.getState(); switch (state) { case STARTED: return IServer.STATE_STARTED; case UPDATING: return IServer.STATE_STARTING; case STOPPED: return IServer.STATE_STOPPED; } } return IServer.STATE_UNKNOWN; }
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 void stopApplication(String appName) { CloudApplication app = getApplication(appName); if (app.getState() != CloudApplication.AppState.STOPPED) { HashMap<String, Object> appRequest = new HashMap<String, Object>(); appRequest.put("state", CloudApplication.AppState.STOPPED); getRestTemplate().put(getUrl("/v2/apps/{guid}"), appRequest, app.getMeta().getGuid()); } }
@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); }
@Override public void stopApplication(String appName) { CloudApplication app = getApplication(appName); if (app.getState() != CloudApplication.AppState.STOPPED) { HashMap<String, Object> appRequest = new HashMap<String, Object>(); appRequest.put("state", CloudApplication.AppState.STOPPED); getRestTemplate().put(getUrl("/v2/apps/{guid}"), appRequest, app.getMeta() .getGuid()); } }
@Override public ApplicationStats getApplicationStats(String appName) { CloudApplication app = getApplication(appName); return doGetApplicationStats(app.getMeta() .getGuid(), app.getState()); }
@Override public InstancesInfo getApplicationInstances(CloudApplication app) { if (app.getState() .equals(CloudApplication.AppState.STARTED)) { return doGetApplicationInstances(app.getMeta() .getGuid()); } return null; }
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; } }
@Override public ApplicationStats getApplicationStats(String appName) { CloudApplication app = getApplication(appName); return doGetApplicationStats(app.getMeta().getGuid(), app.getState()); }
@Override public InstancesInfo getApplicationInstances(CloudApplication app) { if (app.getState().equals(CloudApplication.AppState.STARTED)) { return doGetApplicationInstances(app.getMeta().getGuid()); } return null; }
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; } }
@Override public StartingInfo startApplication(String appName) { CloudApplication app = getApplication(appName); if (app.getState() != CloudApplication.AppState.STARTED) { HashMap<String, Object> appRequest = new HashMap<String, Object>(); appRequest.put("state", CloudApplication.AppState.STARTED); HttpEntity<Object> requestEntity = new HttpEntity<Object>(appRequest); ResponseEntity<String> entity = getRestTemplate().exchange(getUrl("/v2/apps/{guid}?stage_async=true"), HttpMethod.PUT, requestEntity, String.class, app.getMeta() .getGuid()); HttpHeaders headers = entity.getHeaders(); // Return a starting info, even with a null staging log value, as a non-null starting info // indicates that the response entity did have headers. The API contract is to return starting info // if there are headers in the response, null otherwise. if (headers != null && !headers.isEmpty()) { String stagingFile = headers.getFirst("x-app-staging-log"); if (stagingFile != null) { try { stagingFile = URLDecoder.decode(stagingFile, "UTF-8"); } catch (UnsupportedEncodingException e) { logger.error("unexpected inability to UTF-8 decode", e); } } // Return the starting info even if decoding failed or staging file is null return new StartingInfo(stagingFile); } } return null; }
@Override public StartingInfo startApplication(String appName) { CloudApplication app = getApplication(appName); if (app.getState() != CloudApplication.AppState.STARTED) { HashMap<String, Object> appRequest = new HashMap<String, Object>(); appRequest.put("state", CloudApplication.AppState.STARTED); HttpEntity<Object> requestEntity = new HttpEntity<Object>( appRequest); ResponseEntity<String> entity = getRestTemplate().exchange( getUrl("/v2/apps/{guid}?stage_async=true"), HttpMethod.PUT, requestEntity, String.class, app.getMeta().getGuid()); HttpHeaders headers = entity.getHeaders(); // Return a starting info, even with a null staging log value, as a non-null starting info // indicates that the response entity did have headers. The API contract is to return starting info // if there are headers in the response, null otherwise. if (headers != null && !headers.isEmpty()) { String stagingFile = headers.getFirst("x-app-staging-log"); if (stagingFile != null) { try { stagingFile = URLDecoder.decode(stagingFile, "UTF-8"); } catch (UnsupportedEncodingException e) { logger.error("unexpected inability to UTF-8 decode", e); } } // Return the starting info even if decoding failed or staging file is null return new StartingInfo(stagingFile); } } return null; }
protected String runInWait(IProgressMonitor monitor) throws CoreException { if (monitor.isCanceled()) { return null; } SubMonitor subMonitor = SubMonitor.convert(monitor); CloudApplication app = null; try { app = cloudServer.getBehaviour().getCloudApplication(appModule.getDeployedApplicationName(), subMonitor.newChild(50)); } catch (CoreException e) { // Handle app errors separately CloudFoundryPlugin.logError(e); } // Stop checking for the file if the application no longer // exists or is not running if (app != null && app.getState() == AppState.STARTED) { return cloudServer.getBehaviour().getFile(appModule.getDeployedApplicationName(), 0, outputFilePath, subMonitor.newChild(50)); } else { return null; } }
@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; } }