Skip to content

Commit

Permalink
Copy paste elastic agent extension from v4 to v5
Browse files Browse the repository at this point in the history
  • Loading branch information
GaneshSPatil committed Mar 8, 2019
1 parent ee03b27 commit b3bdfbc
Show file tree
Hide file tree
Showing 12 changed files with 1,202 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata;
import com.thoughtworks.go.plugin.access.elastic.v3.ElasticAgentExtensionV3;
import com.thoughtworks.go.plugin.access.elastic.v4.ElasticAgentExtensionV4;
import com.thoughtworks.go.plugin.access.elastic.v5.ElasticAgentExtensionV5;
import com.thoughtworks.go.plugin.api.response.validation.ValidationResult;
import com.thoughtworks.go.plugin.domain.common.PluginConfiguration;
import com.thoughtworks.go.plugin.domain.elastic.Capabilities;
Expand All @@ -40,17 +41,19 @@

@Component
public class ElasticAgentExtension extends AbstractExtension {
public static final List<String> SUPPORTED_VERSIONS = Arrays.asList(ElasticAgentExtensionV3.VERSION, ElasticAgentExtensionV4.VERSION);
public static final List<String> SUPPORTED_VERSIONS = Arrays.asList(ElasticAgentExtensionV3.VERSION, ElasticAgentExtensionV4.VERSION, ElasticAgentExtensionV5.VERSION);
private final Map<String, VersionedElasticAgentExtension> elasticAgentExtensionMap = new HashMap<>();

@Autowired
public ElasticAgentExtension(PluginManager pluginManager, ExtensionsRegistry extensionsRegistry) {
super(pluginManager, extensionsRegistry, new PluginRequestHelper(pluginManager, SUPPORTED_VERSIONS, ELASTIC_AGENT_EXTENSION), ELASTIC_AGENT_EXTENSION);
elasticAgentExtensionMap.put(ElasticAgentExtensionV3.VERSION, new ElasticAgentExtensionV3(pluginRequestHelper));
elasticAgentExtensionMap.put(ElasticAgentExtensionV4.VERSION, new ElasticAgentExtensionV4(pluginRequestHelper));
elasticAgentExtensionMap.put(ElasticAgentExtensionV5.VERSION, new ElasticAgentExtensionV5(pluginRequestHelper));

registerHandler(ElasticAgentExtensionV3.VERSION, new PluginSettingsJsonMessageHandler1_0());
registerHandler(ElasticAgentExtensionV4.VERSION, new PluginSettingsJsonMessageHandler1_0());
registerHandler(ElasticAgentExtensionV5.VERSION, new PluginSettingsJsonMessageHandler1_0());
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2019 ThoughtWorks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.thoughtworks.go.plugin.access.elastic.v5;

import com.thoughtworks.go.plugin.access.elastic.DataConverter;
import com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata;

class AgentMetadataConverterV5 implements DataConverter<AgentMetadata, AgentMetadataDTO> {
@Override
public AgentMetadata fromDTO(AgentMetadataDTO agentMetadataDTO) {
return new AgentMetadata(agentMetadataDTO.elasticAgentId(), agentMetadataDTO.agentState(), agentMetadataDTO.buildState(), agentMetadataDTO.configState());
}

@Override
public AgentMetadataDTO toDTO(AgentMetadata agentMetadata) {
return new AgentMetadataDTO(agentMetadata.elasticAgentId(), agentMetadata.agentState(), agentMetadata.buildState(), agentMetadata.configState());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright 2019 ThoughtWorks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.thoughtworks.go.plugin.access.elastic.v5;

import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import java.io.Serializable;

class AgentMetadataDTO implements Serializable {
private static final Gson GSON = new GsonBuilder().
excludeFieldsWithoutExposeAnnotation().
serializeNulls().
setFieldNamingStrategy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).
create();

@Expose
@SerializedName("agent_id")
private final String elasticAgentId;
@Expose
@SerializedName("agent_state")
private final String agentState;
@Expose
@SerializedName("build_state")
private final String buildState;
@Expose
@SerializedName("config_state")
private final String configState;

public AgentMetadataDTO(String elasticAgentId, String agentState, String buildState, String configState) {
this.elasticAgentId = elasticAgentId;
this.agentState = agentState;
this.buildState = buildState;
this.configState = configState;
}

public String elasticAgentId() {
return elasticAgentId;
}

public String agentState() {
return agentState;
}

public String buildState() {
return buildState;
}

public String configState() {
return configState;
}

public JsonElement toJSON() {
return GSON.toJsonTree(this);
}

@Override
public String toString() {
return "AgentMetadata{" +
"elasticAgentId='" + elasticAgentId + '\'' +
", agentState='" + agentState + '\'' +
", buildState='" + buildState + '\'' +
", configState='" + configState + '\'' +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

AgentMetadataDTO that = (AgentMetadataDTO) o;

if (elasticAgentId != null ? !elasticAgentId.equals(that.elasticAgentId) : that.elasticAgentId != null)
return false;
if (agentState != null ? !agentState.equals(that.agentState) : that.agentState != null) return false;
if (buildState != null ? !buildState.equals(that.buildState) : that.buildState != null) return false;
return configState != null ? configState.equals(that.configState) : that.configState == null;

}

@Override
public int hashCode() {
int result = elasticAgentId != null ? elasticAgentId.hashCode() : 0;
result = 31 * result + (agentState != null ? agentState.hashCode() : 0);
result = 31 * result + (buildState != null ? buildState.hashCode() : 0);
result = 31 * result + (configState != null ? configState.hashCode() : 0);
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2019 ThoughtWorks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.thoughtworks.go.plugin.access.elastic.v5;

import com.thoughtworks.go.plugin.access.elastic.DataConverter;
import com.thoughtworks.go.plugin.domain.elastic.Capabilities;

class CapabilitiesConverterV5 implements DataConverter<Capabilities, CapabilitiesDTO> {
@Override
public Capabilities fromDTO(CapabilitiesDTO capabilitiesDTO) {
return new Capabilities(capabilitiesDTO.supportsStatusReport(), capabilitiesDTO.supportsAgentStatusReport());
}

@Override
public CapabilitiesDTO toDTO(Capabilities object) {
throw unsupportedOperationException(object.getClass().getName(), CapabilitiesDTO.class.getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2019 ThoughtWorks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.thoughtworks.go.plugin.access.elastic.v5;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

class CapabilitiesDTO {
private static final Gson GSON = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
@Expose
@SerializedName("supports_status_report")
private boolean supportsStatusReport;

@Expose
@SerializedName("supports_agent_status_report")
private boolean supportsAgentStatusReport;

public boolean supportsStatusReport() {
return supportsStatusReport;
}

public boolean supportsAgentStatusReport() {
return supportsAgentStatusReport;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CapabilitiesDTO)) return false;

CapabilitiesDTO that = (CapabilitiesDTO) o;

if (supportsStatusReport != that.supportsStatusReport) return false;
return supportsAgentStatusReport == that.supportsAgentStatusReport;
}

@Override
public int hashCode() {
int result = (supportsStatusReport ? 1 : 0);
result = 31 * result + (supportsAgentStatusReport ? 1 : 0);
return result;
}
}
Loading

0 comments on commit b3bdfbc

Please sign in to comment.