-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump up elastic agent extension version to v5 (#106)
* implement migrate config call * fix elastic agent profile related api calls * Implement cluster profile metadata and view call * Implement validate cluster profile call * Implement create agent call using cluster profiles passed from request body * Implement should assign work call using cluster profiles passed from request body * Implement job completion call using cluster profiles passed from request body * Implement capabilities * refresh instances at kubernetes plugin * implement cluster status report call * implement agent status report call * implement server ping request * Modify refresh all to accept plugin settings instead of plugin requests * Remove get plugin settings api call * remove unnecessary plugin settings related calls * Fix issue with gson serailization * Handle cluster profile changed API call * Add test to verify same uuid is generated for cluster profile properties
- Loading branch information
1 parent
d812b4c
commit 54388f8
Showing
61 changed files
with
2,302 additions
and
891 deletions.
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
105 changes: 105 additions & 0 deletions
105
src/main/java/cd/go/contrib/elasticagent/ClusterProfile.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,105 @@ | ||
/* | ||
* 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 cd.go.contrib.elasticagent; | ||
|
||
import com.google.gson.annotations.Expose; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
import java.util.HashMap; | ||
import java.util.Objects; | ||
|
||
import static cd.go.contrib.elasticagent.utils.Util.GSON; | ||
|
||
public class ClusterProfile { | ||
@Expose | ||
@SerializedName("id") | ||
private String id; | ||
|
||
@Expose | ||
@SerializedName("plugin_id") | ||
private String pluginId; | ||
|
||
@Expose | ||
@SerializedName("properties") | ||
private ClusterProfileProperties clusterProfileProperties; | ||
|
||
|
||
public ClusterProfile() { | ||
} | ||
|
||
public ClusterProfile(String id, String pluginId, PluginSettings pluginSettings) { | ||
this.id = id; | ||
this.pluginId = pluginId; | ||
setClusterProfileProperties(pluginSettings); | ||
} | ||
|
||
public static ClusterProfile fromJSON(String json) { | ||
return GSON.fromJson(json, ClusterProfile.class); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ClusterProfile that = (ClusterProfile) o; | ||
return Objects.equals(id, that.id) && | ||
Objects.equals(pluginId, that.pluginId) && | ||
Objects.equals(clusterProfileProperties, that.clusterProfileProperties); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, pluginId, clusterProfileProperties); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ClusterProfile{" + | ||
"id='" + id + '\'' + | ||
", pluginId='" + pluginId + '\'' + | ||
", clusterProfileProperties=" + clusterProfileProperties + | ||
'}'; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getPluginId() { | ||
return pluginId; | ||
} | ||
|
||
public ClusterProfileProperties getClusterProfileProperties() { | ||
return clusterProfileProperties; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public void setPluginId(String pluginId) { | ||
this.pluginId = pluginId; | ||
} | ||
|
||
public void setClusterProfileProperties(ClusterProfileProperties clusterProfileProperties) { | ||
this.clusterProfileProperties = clusterProfileProperties; | ||
} | ||
|
||
public void setClusterProfileProperties(PluginSettings pluginSettings) { | ||
this.clusterProfileProperties = ClusterProfileProperties.fromConfiguration(GSON.fromJson(GSON.toJson(pluginSettings), HashMap.class)); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/cd/go/contrib/elasticagent/ClusterProfileProperties.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,48 @@ | ||
/* | ||
* 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 cd.go.contrib.elasticagent; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import static cd.go.contrib.elasticagent.utils.Util.GSON; | ||
|
||
public class ClusterProfileProperties extends PluginSettings { | ||
public ClusterProfileProperties() { | ||
} | ||
|
||
public ClusterProfileProperties(String goServerUrl, String clusterUrl, String clusterCACertData) { | ||
super(goServerUrl, clusterUrl, clusterCACertData); | ||
} | ||
|
||
public static ClusterProfileProperties fromJSON(String json) { | ||
return GSON.fromJson(json, ClusterProfileProperties.class); | ||
} | ||
|
||
public static ClusterProfileProperties fromConfiguration(Map<String, String> clusterProfileProperties) { | ||
return GSON.fromJson(GSON.toJson(clusterProfileProperties), ClusterProfileProperties.class); | ||
} | ||
|
||
public String uuid() { | ||
return Integer.toHexString(Objects.hash(this)); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return super.toString(); | ||
} | ||
} |
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
105 changes: 105 additions & 0 deletions
105
src/main/java/cd/go/contrib/elasticagent/ElasticAgentProfile.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,105 @@ | ||
/* | ||
* 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 cd.go.contrib.elasticagent; | ||
|
||
import com.google.gson.annotations.Expose; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
import java.util.HashMap; | ||
import java.util.Objects; | ||
|
||
import static cd.go.contrib.elasticagent.utils.Util.GSON; | ||
|
||
public class ElasticAgentProfile { | ||
@Expose | ||
@SerializedName("id") | ||
private String id; | ||
|
||
@Expose | ||
@SerializedName("plugin_id") | ||
private String pluginId; | ||
|
||
@Expose | ||
@SerializedName("cluster_profile_id") | ||
private String clusterProfileId; | ||
|
||
@Expose | ||
@SerializedName("properties") | ||
private HashMap<String, String> properties; | ||
|
||
public static ElasticAgentProfile fromJSON(String json) { | ||
return GSON.fromJson(json, ElasticAgentProfile.class); | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getPluginId() { | ||
return pluginId; | ||
} | ||
|
||
public String getClusterProfileId() { | ||
return clusterProfileId; | ||
} | ||
|
||
public HashMap<String, String> getProperties() { | ||
return properties; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public void setPluginId(String pluginId) { | ||
this.pluginId = pluginId; | ||
} | ||
|
||
public void setClusterProfileId(String clusterProfileId) { | ||
this.clusterProfileId = clusterProfileId; | ||
} | ||
|
||
public void setProperties(HashMap<String, String> properties) { | ||
this.properties = properties; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ElasticAgentProfile that = (ElasticAgentProfile) o; | ||
return Objects.equals(id, that.id) && | ||
Objects.equals(pluginId, that.pluginId) && | ||
Objects.equals(clusterProfileId, that.clusterProfileId) && | ||
Objects.equals(properties, that.properties); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, pluginId, clusterProfileId, properties); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ElasticAgentProfile{" + | ||
"id='" + id + '\'' + | ||
", pluginId='" + pluginId + '\'' + | ||
", clusterProfileId='" + clusterProfileId + '\'' + | ||
", properties=" + properties + | ||
'}'; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/cd/go/contrib/elasticagent/GoServerURLMetadata.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,53 @@ | ||
/* | ||
* 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 cd.go.contrib.elasticagent; | ||
|
||
import cd.go.contrib.elasticagent.model.Metadata; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.net.URI; | ||
|
||
|
||
public class GoServerURLMetadata extends Metadata { | ||
private static String GO_SERVER_URL = "go_server_url"; | ||
|
||
public GoServerURLMetadata() { | ||
super(GO_SERVER_URL, true, false); | ||
} | ||
|
||
@Override | ||
public String doValidate(String input) { | ||
String validationResult = super.doValidate(input); | ||
if (StringUtils.isNotBlank(validationResult) || StringUtils.isBlank(input)) { | ||
return validationResult; | ||
} | ||
|
||
try { | ||
URI uri = new URI(input); | ||
if (uri.getHost().equalsIgnoreCase("localhost") || uri.getHost().equalsIgnoreCase("127.0.0.1")) { | ||
return String.format("%s must not be localhost, since this gets resolved on the agents.", GO_SERVER_URL); | ||
} | ||
if (!StringUtils.endsWith(input, "/go")) { | ||
return String.format("%s must be in format https://<GO_SERVER_URL>:<GO_SERVER_PORT>/go.", GO_SERVER_URL); | ||
} | ||
} catch (Exception e) { | ||
return String.format("%s must be a valid URL (https://example.com:8154/go).", GO_SERVER_URL); | ||
} | ||
|
||
return null; | ||
} | ||
} |
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
Oops, something went wrong.