use of com.thoughtworks.go.plugin.api.exceptions.UnhandledRequestTypeException in project go-plugins by gocd.
the class Plugin1 method handle.
@Override
public GoPluginApiResponse handle(GoPluginApiRequest goPluginApiRequest) throws UnhandledRequestTypeException {
if ("configuration".equals(goPluginApiRequest.requestName())) {
HashMap<String, Object> config = new HashMap<>();
HashMap<String, Object> url = new HashMap<>();
url.put("display-order", "0");
url.put("display-name", "Url");
url.put("required", true);
config.put("Url", url);
return DefaultGoPluginApiResponse.success(new GsonBuilder().create().toJson(config));
} else if ("view".equals(goPluginApiRequest.requestName())) {
return getViewRequest();
}
throw new UnhandledRequestTypeException(goPluginApiRequest.requestName());
}
use of com.thoughtworks.go.plugin.api.exceptions.UnhandledRequestTypeException in project go-plugins by gocd.
the class Plugin2 method handle.
@Override
public GoPluginApiResponse handle(GoPluginApiRequest goPluginApiRequest) throws UnhandledRequestTypeException {
if ("configuration".equals(goPluginApiRequest.requestName())) {
HashMap<String, Object> config = new HashMap<>();
HashMap<String, Object> url = new HashMap<>();
url.put("display-order", "0");
url.put("display-name", "Url");
url.put("required", true);
config.put("Url", url);
return DefaultGoPluginApiResponse.success(new GsonBuilder().create().toJson(config));
} else if ("view".equals(goPluginApiRequest.requestName())) {
return getViewRequest();
}
throw new UnhandledRequestTypeException(goPluginApiRequest.requestName());
}
use of com.thoughtworks.go.plugin.api.exceptions.UnhandledRequestTypeException in project go-plugins by gocd.
the class DummyArtifactPlugin method handle.
@Override
public GoPluginApiResponse handle(GoPluginApiRequest request) throws UnhandledRequestTypeException {
final RequestFromServer requestFromServer = RequestFromServer.from(request.requestName());
try {
switch(requestFromServer) {
case REQUEST_GET_CAPABILITIES:
return DefaultGoPluginApiResponse.success("{}");
case REQUEST_STORE_CONFIG_METADATA:
return DefaultGoPluginApiResponse.success(artifactStoreMetadata());
case REQUEST_STORE_CONFIG_VIEW:
return DefaultGoPluginApiResponse.success(new View("/artifact-store.template.html").toJSON());
case REQUEST_STORE_CONFIG_VALIDATE:
return DefaultGoPluginApiResponse.success(ArtifactStoreConfig.from(request.requestBody()).validate().toJSON());
case REQUEST_PUBLISH_ARTIFACT_METADATA:
return DefaultGoPluginApiResponse.success(ArtifactConfig.artifactConfigMetadata());
case REQUEST_PUBLISH_ARTIFACT_VIEW:
return DefaultGoPluginApiResponse.success(new View("/publish-artifact.template.html").toJSON());
case REQUEST_PUBLISH_ARTIFACT_VALIDATE:
return DefaultGoPluginApiResponse.success(ArtifactConfig.from(request.requestBody()).validate().toJSON());
case REQUEST_FETCH_ARTIFACT_METADATA:
return DefaultGoPluginApiResponse.success(FetchArtifact.metadata());
case REQUEST_FETCH_ARTIFACT_VIEW:
return DefaultGoPluginApiResponse.success(new View("/fetch-artifact.template.html").toJSON());
case REQUEST_FETCH_ARTIFACT_VALIDATE:
return DefaultGoPluginApiResponse.success(FetchArtifact.from(request.requestBody()).validate().toJSON());
case REQUEST_PUBLISH_ARTIFACT:
return publishArtifact(PublishArtifactRequest.fromJSON(request.requestBody()));
case REQUEST_FETCH_ARTIFACT:
return fetchArtifact(FetchArtifactRequest.fromJSON(request.requestBody()));
case REQUEST_GET_PLUGIN_ICON:
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("content_type", "image/jpg");
jsonObject.addProperty("data", Base64.getEncoder().encodeToString(ResourceReader.readBytes("/icon.jpg")));
return DefaultGoPluginApiResponse.success(jsonObject.toString());
default:
throw new RuntimeException("Error while executing request" + request.requestName());
}
} catch (Exception e) {
LOG.error("Error while executing request " + request.requestName(), e);
throw new RuntimeException(e);
}
}
use of com.thoughtworks.go.plugin.api.exceptions.UnhandledRequestTypeException in project gocd-ecs-elastic-agent by gocd.
the class ECSElasticPlugin method handle.
@Override
public GoPluginApiResponse handle(GoPluginApiRequest request) {
ClusterProfileProperties clusterProfileProperties;
try {
fetchServerIdFromServer();
LOG.debug("Request from server: " + request.requestName());
switch(Request.fromString(request.requestName())) {
case PLUGIN_SETTINGS_GET_ICON:
return new GetPluginSettingsIconExecutor().execute();
case REQUEST_GET_ELASTIC_AGENT_PROFILE_METADATA:
return new GetProfileMetadataExecutor().execute();
case REQUEST_GET_ELASTIC_AGENT_PROFILE_VIEW:
return new GetProfileViewExecutor().execute();
case REQUEST_VALIDATE_ELASTIC_AGENT_PROFILE:
return ProfileValidateRequest.fromJSON(request.requestBody()).executor().execute();
case REQUEST_GET_CLUSTER_PROFILE_METADATA:
return new GetClusterProfileMetadataExecutor().execute();
case REQUEST_GET_CLUSTER_PROFILE_VIEW:
return new GetClusterProfileViewRequestExecutor().execute();
case REQUEST_VALIDATE_CLUSTER_PROFILE_CONFIGURATION:
return ValidateClusterProfileRequest.fromJSON(request.requestBody()).executor().execute();
case REQUEST_CREATE_AGENT:
CreateAgentRequest createAgentRequest = CreateAgentRequest.fromJSON(request.requestBody());
clusterProfileProperties = createAgentRequest.clusterProfileProperties();
refreshInstancesForCluster(clusterProfileProperties);
return createAgentRequest.executor(getAgentInstancesFor(clusterProfileProperties), pluginRequest, getEventStreamFor(clusterProfileProperties)).execute();
case REQUEST_SHOULD_ASSIGN_WORK:
ShouldAssignWorkRequest shouldAssignWorkRequest = ShouldAssignWorkRequest.fromJSON(request.requestBody());
clusterProfileProperties = shouldAssignWorkRequest.clusterProfileProperties();
refreshInstancesForCluster(clusterProfileProperties);
return shouldAssignWorkRequest.executor(getAgentInstancesFor(clusterProfileProperties)).execute();
case REQUEST_JOB_COMPLETION:
JobCompletionRequest jobCompletionRequest = JobCompletionRequest.fromJSON(request.requestBody());
clusterProfileProperties = jobCompletionRequest.clusterProfileProperties();
refreshInstancesForCluster(clusterProfileProperties);
return jobCompletionRequest.executor(getAgentInstancesFor(clusterProfileProperties), pluginRequest).execute();
case REQUEST_SERVER_PING:
ServerPingRequest serverPingRequest = ServerPingRequest.fromJSON(request.requestBody());
List<ClusterProfileProperties> listOfClusterProfileProperties = serverPingRequest.allClusterProfileProperties();
refreshInstancesForAllClusters(listOfClusterProfileProperties);
return serverPingRequest.executor(clusterSpecificAgentInstances, pluginRequest).execute();
case REQUEST_CLUSTER_STATUS_REPORT:
ClusterStatusReportRequest clusterStatusReportRequest = ClusterStatusReportRequest.fromJSON(request.requestBody());
clusterProfileProperties = clusterStatusReportRequest.clusterProfileProperties();
refreshInstancesForCluster(clusterProfileProperties);
return clusterStatusReportRequest.executor(getAgentInstancesFor(clusterProfileProperties), getEventStreamFor(clusterProfileProperties)).execute();
case REQUEST_AGENT_STATUS_REPORT:
AgentStatusReportRequest statusReportRequest = AgentStatusReportRequest.fromJSON(request.requestBody());
clusterProfileProperties = statusReportRequest.clusterProfileProperties();
refreshInstancesForCluster(clusterProfileProperties);
return statusReportRequest.executor(getAgentInstancesFor(clusterProfileProperties)).execute();
case REQUEST_GET_CAPABILITIES:
return new GetCapabilitiesExecutor().execute();
case REQUEST_CLUSTER_PROFILE_CHANGED:
return new DefaultGoPluginApiResponse(200);
case REQUEST_MIGRATE_CONFIGURATION:
return MigrateConfigurationRequest.fromJSON(request.requestBody()).executor().execute();
default:
throw new UnhandledRequestTypeException(request.requestName());
}
} catch (AmazonEC2Exception e) {
LOG.error("Failed to handle request " + request.requestName() + " due to:" + e.getMessage());
return DefaultGoPluginApiResponse.error("Failed to handle request " + request.requestName() + " due to:" + e.getMessage());
} catch (Exception e) {
LOG.error("Failed to handle request " + request.requestName() + " due to:", e);
return DefaultGoPluginApiResponse.error("Failed to handle request " + request.requestName() + " due to:" + e.getMessage());
}
}
Aggregations