forked from gocd/gocd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy paste elastic agent extension from v4 to v5
- Loading branch information
1 parent
ee03b27
commit b3bdfbc
Showing
12 changed files
with
1,202 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
.../src/main/java/com/thoughtworks/go/plugin/access/elastic/v5/AgentMetadataConverterV5.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
...n-access/src/main/java/com/thoughtworks/go/plugin/access/elastic/v5/AgentMetadataDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...s/src/main/java/com/thoughtworks/go/plugin/access/elastic/v5/CapabilitiesConverterV5.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...in-access/src/main/java/com/thoughtworks/go/plugin/access/elastic/v5/CapabilitiesDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.