From 7944b751189262354b00ccd566ce6b819be776f9 Mon Sep 17 00:00:00 2001 From: Harish Karthic Date: Tue, 4 Jan 2022 15:43:33 +0000 Subject: [PATCH] Added support for Distributed task Api (#12) * Update `ChangeLog` [#11](https://github.com/hkarthik7/azure-devops-java-sdk/pull/11) * Added support for `Distributed task Api` * Added comments and updated documents for `Distributed task Api` * Updated unit tests * Updated unit tests * Updated unit tests --- CHANGELOG.md | 7 +- .../main/java/org/azd/common/ApiVersion.java | 2 + .../distributedtask/DistributedTaskApi.java | 867 ++++++++++++++++++ .../types/DeploymentGroup.java | 133 +++ .../types/DeploymentGroups.java | 33 + .../types/DeploymentMachine.java | 77 ++ .../types/EnvironmentInstance.java | 150 +++ .../types/EnvironmentInstances.java | 33 + .../types/EnvironmentResourceReference.java | 75 ++ .../azd/distributedtask/types/TaskAgent.java | 286 ++++++ .../types/TaskAgentAuthorization.java | 59 ++ .../types/TaskAgentCloudRequest.java | 158 ++++ .../types/TaskAgentJobRequest.java | 427 +++++++++ .../types/TaskAgentPoolReference.java | 129 +++ .../types/TaskAgentPublicKey.java | 47 + .../types/TaskAgentReference.java | 129 +++ .../types/TaskAgentUpdate.java | 102 +++ .../types/TaskAgentUpdateReason.java | 31 + .../azd/distributedtask/types/TaskAgents.java | 33 + .../types/TaskOrchestrationOwner.java | 45 + .../distributedtask/types/VariableGroup.java | 189 ++++ .../types/VariableGroupDefinition.java | 96 ++ .../types/VariableGroupProjectReference.java | 60 ++ .../types/VariableGroupProviderData.java | 39 + .../distributedtask/types/VariableGroups.java | 33 + .../enums/DeploymentGroupActionFilter.java | 16 + .../org/azd/enums/DeploymentGroupExpands.java | 11 + .../org/azd/enums/EnvironmentExpands.java | 17 + .../azd/enums/VariableGroupActionFilter.java | 10 + .../azd/enums/VariableGroupQueryOrder.java | 16 + .../java/org/azd/enums/VariableGroupType.java | 13 + .../java/org/azd/interfaces/AzDClient.java | 2 + .../interfaces/DistributedTaskDetails.java | 54 ++ .../main/java/org/azd/utils/AzDClientApi.java | 9 + azd/src/test/java/org/azd/BuildApiTest.java | 10 +- .../java/org/azd/DistributedTaskApiTest.java | 195 ++++ azd/src/test/java/org/azd/PipelinesTest.java | 12 +- 37 files changed, 3592 insertions(+), 13 deletions(-) create mode 100644 azd/src/main/java/org/azd/distributedtask/DistributedTaskApi.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/DeploymentGroup.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/DeploymentGroups.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/DeploymentMachine.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/EnvironmentInstance.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/EnvironmentInstances.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/EnvironmentResourceReference.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/TaskAgent.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/TaskAgentAuthorization.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/TaskAgentCloudRequest.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/TaskAgentJobRequest.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/TaskAgentPoolReference.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/TaskAgentPublicKey.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/TaskAgentReference.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/TaskAgentUpdate.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/TaskAgentUpdateReason.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/TaskAgents.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/TaskOrchestrationOwner.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/VariableGroup.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/VariableGroupDefinition.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/VariableGroupProjectReference.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/VariableGroupProviderData.java create mode 100644 azd/src/main/java/org/azd/distributedtask/types/VariableGroups.java create mode 100644 azd/src/main/java/org/azd/enums/DeploymentGroupActionFilter.java create mode 100644 azd/src/main/java/org/azd/enums/DeploymentGroupExpands.java create mode 100644 azd/src/main/java/org/azd/enums/EnvironmentExpands.java create mode 100644 azd/src/main/java/org/azd/enums/VariableGroupActionFilter.java create mode 100644 azd/src/main/java/org/azd/enums/VariableGroupQueryOrder.java create mode 100644 azd/src/main/java/org/azd/enums/VariableGroupType.java create mode 100644 azd/src/main/java/org/azd/interfaces/DistributedTaskDetails.java create mode 100644 azd/src/test/java/org/azd/DistributedTaskApiTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index bd9b63bb..78908beb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,14 @@ # Changelog +## 2.5.9 +- Expanded the WorkItemTrackingDetails interface with two updateWorkItem + methods and added hyperlinks support. [Associated PR](https://github.com/hkarthik7/azure-devops-java-sdk/pull/10) +- Added support for **Distributed Task Api** + ## 2.5.8 - Merged PR: [Added support for **policy Api** #8](https://github.com/hkarthik7/azure-devops-java-sdk/pull/8) - Merged PR: [Added support for **build tags** API #9](https://github.com/hkarthik7/azure-devops-java-sdk/pull/9) - Added support for Pipelines API. -- Expanded the WorkItemTrackingDetails interface with two updateWorkItem -methods and added hyperlinks support. [Associated PR](https://github.com/hkarthik7/azure-devops-java-sdk/pull/10) ## 2.5.7 - Created a helper method in **BuildApi** to easily create/clone a pipeline. diff --git a/azd/src/main/java/org/azd/common/ApiVersion.java b/azd/src/main/java/org/azd/common/ApiVersion.java index 92b9bc0b..f2842400 100644 --- a/azd/src/main/java/org/azd/common/ApiVersion.java +++ b/azd/src/main/java/org/azd/common/ApiVersion.java @@ -11,6 +11,7 @@ public abstract class ApiVersion { public static final String BUILD_DEFINITION_REVISIONS = "6.1-preview.3"; public static final String BUILD_TAGS = "6.1-preview.3"; public static final String CORE = "6.1-preview.1"; + public static final String DISTRIBUTED_TASK = "6.1-preview.1"; public static final String EXTENSION_MANAGEMENT = "6.1-preview.1"; public static final String POLICY = "6.1-preview.1"; public static final String PROJECT = "6.1-preview.4"; @@ -29,6 +30,7 @@ public abstract class ApiVersion { public static final String RELEASE_DEFINITION_HISTORY = "6.1-preview.1"; public static final String SERVICE_ENDPOINTS = "6.1-preview.4"; public static final String SERVICE_HOOKS = "6.1-preview.1"; + public static final String VARIABLE_GROUPS = "6.1-preview.2"; public static final String WIKI = "6.1-preview.2"; public static final String WORK = "6.1-preview.1"; public static final String WORK_ITEM_TRACKING = "6.1-preview.3"; diff --git a/azd/src/main/java/org/azd/distributedtask/DistributedTaskApi.java b/azd/src/main/java/org/azd/distributedtask/DistributedTaskApi.java new file mode 100644 index 00000000..528a5086 --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/DistributedTaskApi.java @@ -0,0 +1,867 @@ +package org.azd.distributedtask; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.azd.common.ApiVersion; +import org.azd.connection.Connection; +import org.azd.core.CoreApi; +import org.azd.distributedtask.types.*; +import org.azd.enums.*; +import org.azd.exceptions.AzDException; +import org.azd.exceptions.ConnectionException; +import org.azd.helpers.JsonMapper; +import org.azd.interfaces.DistributedTaskDetails; +import org.azd.release.types.ProjectReference; + +import java.util.*; + +import static org.azd.utils.Client.send; + +/*** + * DistributedTaskApi class to manage Agents, Deployment groups, Environments and Variable groups API + */ +public class DistributedTaskApi implements DistributedTaskDetails { + /*** + * Connection object + */ + private final Connection CONNECTION; + private final JsonMapper MAPPER = new JsonMapper(); + private final String AREA = "distributedtask"; + private final String DISTRIBUTEDTASK = "a85b8835-c1a1-4aac-ae97-1c3d0ba72dbd"; + + /*** + * Pass the connection object + * @param connection Connection object + */ + public DistributedTaskApi(Connection connection) { this.CONNECTION = connection; } + + /*** + * Delete an agent. + * @param poolId The pool ID to remove the agent from + * @param agentId The agent ID to remove + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public void deleteAgent(int poolId, int agentId) throws ConnectionException, AzDException { + try { + String r = send(RequestMethod.DELETE, CONNECTION, DISTRIBUTEDTASK, null, + AREA + "/pools", poolId + "/agents/" + agentId, null, ApiVersion.DISTRIBUTED_TASK, null, null); + + if (!r.isEmpty()) MAPPER.mapJsonResponse(r, Map.class); + } catch (ConnectionException | AzDException e) { + throw e; + } + } + + /*** + * Get information about an agent. + * @param poolId The agent pool containing the agent + * @param agentId The agent ID to get information about + * @return A TaskAgent object {@link TaskAgent} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public TaskAgent getAgent(int poolId, int agentId) throws ConnectionException, AzDException { + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, null, + AREA + "/pools", poolId + "/agents/" + agentId, null, ApiVersion.DISTRIBUTED_TASK, null, null); + + return MAPPER.mapJsonResponse(r, TaskAgent.class); + } + + /*** + * Get information about an agent. + * @param poolId The agent pool containing the agent + * @param agentId The agent ID to get information about + * @param includeAssignedRequest Whether to include details about the agent's current work + * @param includeCapabilities Whether to include the agent's capabilities in the response + * @param includeLastCompletedRequest Whether to include details about the agents' most recent completed work + * @param propertyFilters Filter which custom properties will be returned + * @return A TaskAgent object {@link TaskAgent} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public TaskAgent getAgent(int poolId, int agentId, boolean includeAssignedRequest, boolean includeCapabilities, + boolean includeLastCompletedRequest, String[] propertyFilters) throws ConnectionException, AzDException { + var q = new HashMap(){{ + put("includeAssignedRequest", includeAssignedRequest); + put("includeCapabilities", includeCapabilities); + put("includeLastCompletedRequest", includeLastCompletedRequest); + put("propertyFilters", String.join(",", propertyFilters)); + }}; + + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, null, + AREA + "/pools", poolId + "/agents/" + agentId, null, ApiVersion.DISTRIBUTED_TASK, q, null); + + return MAPPER.mapJsonResponse(r, TaskAgent.class); + } + + /*** + * Get a list of agents. + * @param poolId The agent pool containing the agents + * @return TaskAgents object {@link TaskAgents} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public TaskAgents getAgents(int poolId) throws ConnectionException, AzDException { + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, null, + AREA + "/pools", poolId + "/agents", null, ApiVersion.DISTRIBUTED_TASK, null, null); + + return MAPPER.mapJsonResponse(r, TaskAgents.class); + } + + /*** + * Get a list of agents. + * @param poolId The agent pool containing the agents + * @param agentName Filter on agent name + * @param demands Filter by demands the agents can satisfy + * @param includeAssignedRequest Whether to include details about the agents' current work + * @param includeCapabilities Whether to include the agents' capabilities in the response + * @param includeLastCompletedRequest Whether to include details about the agents' most recent completed work + * @param propertyFilters Filter which custom properties will be returned + * @return TaskAgents object {@link TaskAgents} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public TaskAgents getAgents(int poolId, String agentName, String[] demands, boolean includeAssignedRequest, + boolean includeCapabilities, boolean includeLastCompletedRequest, String[] propertyFilters) + throws ConnectionException, AzDException { + var q = new HashMap(){{ + put("agentName", agentName); + put("demands", String.join(",", demands)); + put("includeAssignedRequest", includeAssignedRequest); + put("includeCapabilities", includeCapabilities); + put("includeLastCompletedRequest", includeLastCompletedRequest); + put("propertyFilters", String.join(",", propertyFilters)); + }}; + + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, null, + AREA + "/pools", poolId + "/agents", null, ApiVersion.DISTRIBUTED_TASK, q, null); + + return MAPPER.mapJsonResponse(r, TaskAgents.class); + } + + /*** + * Update agent details. + * @param poolId The agent pool to use + * @param agentId The agent to update + * @param requestBody Map of request body. + *

+ * Visit https://docs.microsoft.com/en-us/rest/api/azure/devops/distributedtask/agents/update?view=azure-devops-rest-6.1#request-body for more details. + *

+ * @return A TaskAgent object {@link TaskAgent} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public TaskAgent updateAgent(int poolId, int agentId, Map requestBody) throws ConnectionException, AzDException { + String r = send(RequestMethod.PATCH, CONNECTION, DISTRIBUTEDTASK, null, + AREA + "/pools", poolId + "/agents/" + agentId, null, ApiVersion.DISTRIBUTED_TASK, null, requestBody); + + return MAPPER.mapJsonResponse(r, TaskAgent.class); + } + + /*** + * Create a deployment group. + * @param name Name of the deployment group. + * @param description Description of the deployment group. + * @return Deployment group object {@link DeploymentGroup} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public DeploymentGroup addDeploymentGroup(String name, String description) throws ConnectionException, AzDException { + var requestBody = new HashMap(){{ + put("name", name); + put("description", description); + }}; + + String r = send(RequestMethod.POST, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/deploymentgroups", null, null, ApiVersion.DISTRIBUTED_TASK, null, requestBody); + + return MAPPER.mapJsonResponse(r, DeploymentGroup.class); + } + + /*** + * Create a deployment group. + * @param name Name of the deployment group. + * @param description Description of the deployment group. + * @param poolId Identifier of the deployment pool in which deployment agents are registered. + * @return Deployment group object {@link DeploymentGroup} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public DeploymentGroup addDeploymentGroup(String name, String description, int poolId) throws ConnectionException, AzDException { + var requestBody = new HashMap(){{ + put("name", name); + put("description", description); + put("poolId", poolId); + }}; + + String r = send(RequestMethod.POST, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/deploymentgroups", null, null, ApiVersion.DISTRIBUTED_TASK, null, requestBody); + + return MAPPER.mapJsonResponse(r, DeploymentGroup.class); + } + + /*** + * Delete a deployment group. + * @param deploymentGroupId ID of the deployment group to be deleted. + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public void deleteDeploymentGroup(int deploymentGroupId) throws ConnectionException, AzDException { + try { + String r = send(RequestMethod.DELETE, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/deploymentgroups", Integer.toString(deploymentGroupId), null, ApiVersion.DISTRIBUTED_TASK, null, null); + + if (!r.isEmpty()) MAPPER.mapJsonResponse(r, Map.class); + } catch (ConnectionException | AzDException e) { + throw e; + } + } + + /*** + * Get a deployment group by its ID. + * @param deploymentGroupId ID of the deployment group to be deleted. + * @return Deployment group object {@link DeploymentGroup} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public DeploymentGroup getDeploymentGroup(int deploymentGroupId) throws ConnectionException, AzDException { + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/deploymentgroups", Integer.toString(deploymentGroupId), null, ApiVersion.DISTRIBUTED_TASK, null, null); + + return MAPPER.mapJsonResponse(r, DeploymentGroup.class); + } + + /*** + * Get a deployment group by its ID. + * @param deploymentGroupId ID of the deployment group to be deleted. + * @param expand Include these additional details in the returned object. + * @param actionFilter Get the deployment group only if this action can be performed on it. + * @return Deployment group object {@link DeploymentGroup} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public DeploymentGroup getDeploymentGroup(int deploymentGroupId, DeploymentGroupExpands expand, DeploymentGroupActionFilter actionFilter) + throws ConnectionException, AzDException { + var q = new HashMap(){{ + put("$expand", expand.toString().toLowerCase()); + put("actionFilter", actionFilter.toString().toLowerCase()); + }}; + + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/deploymentgroups", Integer.toString(deploymentGroupId), null, ApiVersion.DISTRIBUTED_TASK, q, null); + + return MAPPER.mapJsonResponse(r, DeploymentGroup.class); + } + + /*** + * Get a list of deployment groups by name or IDs. + * @return Deployment groups object {@link DeploymentGroups} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public DeploymentGroups getDeploymentGroups() throws ConnectionException, AzDException { + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/deploymentgroups", null, null, ApiVersion.DISTRIBUTED_TASK, null, null); + + return MAPPER.mapJsonResponse(r, DeploymentGroups.class); + } + + /*** + * Get a list of deployment groups by name or IDs. + * @param top Maximum number of deployment groups to return. Default is 1000. + * @return Deployment groups object {@link DeploymentGroups} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public DeploymentGroups getDeploymentGroups(int top) throws ConnectionException, AzDException { + var q = new HashMap(){{ + put("$top", top); + }}; + + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/deploymentgroups", null, null, ApiVersion.DISTRIBUTED_TASK, q, null); + + return MAPPER.mapJsonResponse(r, DeploymentGroups.class); + } + + /*** + * Get a list of deployment groups by name or IDs. + * @param ids Array of Id of deployment groups. + * @return Deployment groups object {@link DeploymentGroups} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public DeploymentGroups getDeploymentGroups(int[] ids) throws ConnectionException, AzDException { + var q = new HashMap(){{ + put("ids", intArrayToString(ids)); + }}; + + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/deploymentgroups", null, null, ApiVersion.DISTRIBUTED_TASK, q, null); + + return MAPPER.mapJsonResponse(r, DeploymentGroups.class); + } + + /*** + * Get a list of deployment groups by name or IDs. + * @param name Name of the deployment group. + * @return Deployment groups object {@link DeploymentGroups} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public DeploymentGroups getDeploymentGroups(String name) throws ConnectionException, AzDException { + var q = new HashMap(){{ + put("name", name); + }}; + + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/deploymentgroups", null, null, ApiVersion.DISTRIBUTED_TASK, q, null); + + return MAPPER.mapJsonResponse(r, DeploymentGroups.class); + } + + /*** + * Get a list of deployment groups by name or IDs. + * @param expand Include these additional details in the returned objects. {@link DeploymentGroupExpands} + * @return Deployment groups object {@link DeploymentGroups} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public DeploymentGroups getDeploymentGroups(DeploymentGroupExpands expand) throws ConnectionException, AzDException { + var q = new HashMap(){{ + put("$expand", expand.toString().toLowerCase()); + }}; + + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/deploymentgroups", null, null, ApiVersion.DISTRIBUTED_TASK, q, null); + + return MAPPER.mapJsonResponse(r, DeploymentGroups.class); + } + + /*** + * Get a list of deployment groups by name or IDs. + * @param expand Include these additional details in the returned objects. {@link DeploymentGroupExpands} + * @param top Maximum number of deployment groups to return. Default is 1000. + * @param actionFilter Get only deployment groups on which this action can be performed. {@link DeploymentGroupActionFilter} + * @param continuationToken Get deployment groups with names greater than this continuationToken lexicographically. + * @param ids Comma separated list of IDs of the deployment groups. + * @param name Name of the deployment group. + * @return Deployment groups object {@link DeploymentGroups} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public DeploymentGroups getDeploymentGroups(DeploymentGroupExpands expand, int top, DeploymentGroupActionFilter actionFilter, + String continuationToken, int[] ids, String name) throws ConnectionException, AzDException { + var q = new HashMap(){{ + put("$expand", expand.toString().toLowerCase()); + put("$top", top); + put("actionFilter", actionFilter.toString().toLowerCase()); + put("continuationToken", continuationToken); + put("ids", intArrayToString(ids)); + put("name", name); + }}; + + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/deploymentgroups", null, null, ApiVersion.DISTRIBUTED_TASK, q, null); + + return MAPPER.mapJsonResponse(r, DeploymentGroups.class); + } + + /*** + * Update a deployment group. + * @param deploymentGroupId ID of the deployment group. + * @param name Name of the deployment group. + * @param description Description of the deployment group. + * @return Deployment group object {@link DeploymentGroup} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public DeploymentGroup updateDeploymentGroup(int deploymentGroupId, String name, String description) throws ConnectionException, AzDException { + var requestBody = new HashMap(){{ + put("name", name); + put("description", description); + }}; + + String r = send(RequestMethod.PATCH, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/deploymentgroups", Integer.toString(deploymentGroupId), null, ApiVersion.DISTRIBUTED_TASK, null, requestBody); + + return MAPPER.mapJsonResponse(r, DeploymentGroup.class); + } + + /*** + * Create an environment. + * @param name Name of the environment. + * @param description Description of the environment. + * @return Environment instance {@link EnvironmentInstance} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public EnvironmentInstance addEnvironment(String name, String description) throws ConnectionException, AzDException { + var requestBody = new HashMap(){{ + put("name", name); + put("description", description); + }}; + + String r = send(RequestMethod.POST, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/environments", null, null, ApiVersion.DISTRIBUTED_TASK, null, requestBody); + + return MAPPER.mapJsonResponse(r, EnvironmentInstance.class); + } + + /*** + * Delete the specified environment. + * @param environmentId ID of the environment. + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public void deleteEnvironment(int environmentId) throws ConnectionException, AzDException { + try { + String r = send(RequestMethod.DELETE, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/environments", Integer.toString(environmentId), null, ApiVersion.DISTRIBUTED_TASK, null, null); + + if (!r.isEmpty()) MAPPER.mapJsonResponse(r, Map.class); + } catch (ConnectionException | AzDException e) { + throw e; + } + } + + /*** + * Get an environment by its ID. + * @param environmentId ID of the environment. + * @return Environment instance {@link EnvironmentInstance} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public EnvironmentInstance getEnvironment(int environmentId) throws ConnectionException, AzDException { + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/environments", Integer.toString(environmentId), null, ApiVersion.DISTRIBUTED_TASK, null, null); + + return MAPPER.mapJsonResponse(r, EnvironmentInstance.class); + } + + /*** + * Get an environment by its ID. + * @param environmentId ID of the environment. + * @param expands Include these additional details in the returned objects. {@link EnvironmentExpands} + * @return Environment instance {@link EnvironmentInstance} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public EnvironmentInstance getEnvironment(int environmentId, EnvironmentExpands expands) throws ConnectionException, AzDException { + var q = new HashMap(){{ + put("expands", expands.toString().toLowerCase()); + }}; + + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/environments", Integer.toString(environmentId), null, ApiVersion.DISTRIBUTED_TASK, q, null); + + return MAPPER.mapJsonResponse(r, EnvironmentInstance.class); + } + + /*** + * Get all environments. + * @return Environment instances array {@link EnvironmentInstances} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public EnvironmentInstances getEnvironments() throws ConnectionException, AzDException { + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/environments", null, null, ApiVersion.DISTRIBUTED_TASK, null, null); + + return MAPPER.mapJsonResponse(r, EnvironmentInstances.class); + } + + /*** + * Get all environments. + * @param top Top environments to list + * @return Environment instances array {@link EnvironmentInstances} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public EnvironmentInstances getEnvironments(int top) throws ConnectionException, AzDException { + var q = new HashMap(){{ + put("$top", top); + }}; + + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/environments", null, null, ApiVersion.DISTRIBUTED_TASK, q, null); + + return MAPPER.mapJsonResponse(r, EnvironmentInstances.class); + } + + /*** + * Get all environments. + * @param name Name of the environment. + * @return Environment instances array {@link EnvironmentInstances} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public EnvironmentInstances getEnvironments(String name) throws ConnectionException, AzDException { + var q = new HashMap(){{ + put("name", name); + }}; + + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/environments", null, null, ApiVersion.DISTRIBUTED_TASK, q, null); + + return MAPPER.mapJsonResponse(r, EnvironmentInstances.class); + } + + /*** + * Get all environments. + * @param top Top environments to list. + * @param continuationToken Get the list of environments paginated. + * @param name Name of the environment. + * @return Environment instances array {@link EnvironmentInstances} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public EnvironmentInstances getEnvironments(int top, String continuationToken, String name) throws ConnectionException, AzDException { + var q = new HashMap(){{ + put("$top", top); + put("continuationToken", continuationToken); + put("name", name); + }}; + + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/environments", null, null, ApiVersion.DISTRIBUTED_TASK, q, null); + + return MAPPER.mapJsonResponse(r, EnvironmentInstances.class); + } + + /*** + * Update the specified environment. + * @param environmentId ID of the environment. + * @param name Name of the environment. + * @param description Description of the environment. + * @return Environment instance {@link EnvironmentInstance} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public EnvironmentInstance updateEnvironment(int environmentId, String name, String description) throws ConnectionException, AzDException { + var requestBody = new HashMap(){{ + put("name", name); + put("description", description); + }}; + + String r = send(RequestMethod.PATCH, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/environments", Integer.toString(environmentId), null, ApiVersion.DISTRIBUTED_TASK, null, requestBody); + + return MAPPER.mapJsonResponse(r, EnvironmentInstance.class); + } + + /*** + * Add a variable group. + * @param variableGroupDefinition Variable group definition {@link VariableGroupDefinition} + * @return Variable group {@link VariableGroup} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public VariableGroup addVariableGroup(VariableGroupDefinition variableGroupDefinition) + throws ConnectionException, AzDException { + var ref = new VariableGroupProjectReference(); + ref.setName(variableGroupDefinition.getName()); + ref.setDescription(variableGroupDefinition.getDescription()); + ref.setProjectReference(variableGroupDefinition.getProjectReference()); + + List o = new ArrayList<>(); + o.add(ref); + + var requestBody = new HashMap(){{ + put("variableGroupProjectReferences", o); + put("name", variableGroupDefinition.getName()); + put("description", variableGroupDefinition.getDescription()); + put("type", variableGroupDefinition.getType()); + put("variables", variableGroupDefinition.getVariables()); + put("providerData", variableGroupDefinition.getProviderData()); + }}; + + String r = send(RequestMethod.POST, CONNECTION, DISTRIBUTEDTASK, null, + AREA + "/variablegroups", null, null, ApiVersion.VARIABLE_GROUPS, null, requestBody); + + return MAPPER.mapJsonResponse(r, VariableGroup.class); + } + + /*** + * Add a variable group. + * @param name Name of the variable group. + * @param description Description for the variable group. + * @param variables Map of variables to add. + * @return Variable group {@link VariableGroup} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public VariableGroup addVariableGroup(String name, String description, Map variables) throws ConnectionException, AzDException { + var definition = new VariableGroupDefinition(); + var projectReference = new ProjectReference(); + var core = new CoreApi(CONNECTION); + var project = core.getProject(CONNECTION.getProject()); + + projectReference.setName(project.getName()); + projectReference.setId(project.getId()); + + definition.setName(name); + definition.setDescription(description); + definition.setVariables(variables); + definition.setProjectReference(projectReference); + definition.setType(VariableGroupType.Vsts); + + return addVariableGroup(definition); + } + + /*** + * Delete a variable group + * @param variableGroupId Id of the variable group. + * @param projectIds String array of project ids. + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public void deleteVariableGroup(int variableGroupId, String[] projectIds) throws ConnectionException, AzDException { + try { + var q = new HashMap(){{ + put("projectIds", String.join(",", projectIds)); + }}; + + String r = send(RequestMethod.DELETE, CONNECTION, DISTRIBUTEDTASK, null, + AREA + "/variablegroups", Integer.toString(variableGroupId), null, ApiVersion.VARIABLE_GROUPS, q, null); + + if (!r.isEmpty()) MAPPER.mapJsonResponse(r, Map.class); + } catch (ConnectionException | AzDException e) { + throw e; + } + } + + /*** + * Get a variable group. + * @param variableGroupId Id of the variable group. + * @return Variable group {@link VariableGroup} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public VariableGroup getVariableGroup(int variableGroupId) throws ConnectionException, AzDException { + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/variablegroups", Integer.toString(variableGroupId), null, ApiVersion.VARIABLE_GROUPS, null, null); + + return MAPPER.mapJsonResponse(r, VariableGroup.class); + } + + /*** + * Get variable groups. + * @return Variable groups object {@link VariableGroups} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public VariableGroups getVariableGroups() throws ConnectionException, AzDException { + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/variablegroups", null, null, ApiVersion.VARIABLE_GROUPS, null, null); + + return MAPPER.mapJsonResponse(r, VariableGroups.class); + } + + /*** + * Get variable groups. + * @param top Number of variable groups to get. + * @return Variable groups object {@link VariableGroups} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public VariableGroups getVariableGroups(int top) throws ConnectionException, AzDException { + var q = new HashMap(){{ + put("$top", top); + }}; + + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/variablegroups", null, null, ApiVersion.VARIABLE_GROUPS, q, null); + + return MAPPER.mapJsonResponse(r, VariableGroups.class); + } + + /*** + * Get variable groups. + * @param groupName Name of variable group. + * @return Variable groups object {@link VariableGroups} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public VariableGroups getVariableGroups(String groupName) throws ConnectionException, AzDException { + var q = new HashMap(){{ + put("groupName", groupName); + }}; + + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/variablegroups", null, null, ApiVersion.VARIABLE_GROUPS, q, null); + + return MAPPER.mapJsonResponse(r, VariableGroups.class); + } + + /*** + * Get variable groups. + * @param top Number of variable groups to get. + * @param actionFilter Action filter for the variable group. It specifies the action which can be performed on the variable groups. {@link VariableGroupActionFilter} + * @param continuationToken Gets the variable groups after the continuation token provided. + * @param groupName Name of variable group. + * @param queryOrder Gets the results in the defined order. Default is 'IdDescending'. {@link VariableGroupQueryOrder} + * @return Variable groups object {@link VariableGroups} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public VariableGroups getVariableGroups(int top, VariableGroupActionFilter actionFilter, int continuationToken, String groupName, + VariableGroupQueryOrder queryOrder) throws ConnectionException, AzDException { + var q = new HashMap(){{ + put("$top", top); + put("actionFilter", actionFilter.toString().toLowerCase()); + put("continuationToken", continuationToken); + put("groupName", groupName); + put("queryOrder", queryOrder.toString().toLowerCase()); + }}; + + String r = send(RequestMethod.GET, CONNECTION, DISTRIBUTEDTASK, CONNECTION.getProject(), + AREA + "/variablegroups", null, null, ApiVersion.VARIABLE_GROUPS, q, null); + + return MAPPER.mapJsonResponse(r, VariableGroups.class); + } + + /*** + * Update a variable group. + * @param groupId Id of the variable group to update. + * @param name Sets name of the variable group. + * @param description Sets description of the variable group. + * @param variables Sets variables contained in the variable group. + * @return Variable group {@link VariableGroup} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public VariableGroup updateVariableGroup(int groupId, String name, String description, Map variables) throws ConnectionException, AzDException { + var definition = new VariableGroupDefinition(); + var projectReference = new ProjectReference(); + var core = new CoreApi(CONNECTION); + var project = core.getProject(CONNECTION.getProject()); + + projectReference.setName(project.getName()); + projectReference.setId(project.getId()); + + definition.setName(name); + definition.setDescription(description); + definition.setVariables(variables); + definition.setProjectReference(projectReference); + definition.setType(VariableGroupType.Vsts); + + return updateVariableGroup(groupId, definition); + } + + /*** + * Update a variable group. + * @param groupId Id of the variable group to update. + * @param variableGroupDefinition Variable group definition {@link VariableGroupDefinition} + * @return Variable group {@link VariableGroup} + * @throws ConnectionException A connection object should be created with Azure DevOps organization name, personal access token + * and project. This validates the connection object and throws exception if it is not provided. + * @throws AzDException Default Api Exception handler. + */ + @Override + public VariableGroup updateVariableGroup(int groupId, VariableGroupDefinition variableGroupDefinition) throws ConnectionException, AzDException { + var ref = new VariableGroupProjectReference(); + ref.setName(variableGroupDefinition.getName()); + ref.setDescription(variableGroupDefinition.getDescription()); + ref.setProjectReference(variableGroupDefinition.getProjectReference()); + + List o = new ArrayList<>(); + o.add(ref); + + var requestBody = new HashMap(){{ + put("variableGroupProjectReferences", o); + put("name", variableGroupDefinition.getName()); + put("description", variableGroupDefinition.getDescription()); + put("type", variableGroupDefinition.getType()); + put("variables", variableGroupDefinition.getVariables()); + put("providerData", variableGroupDefinition.getProviderData()); + }}; + + String r = send(RequestMethod.PUT, CONNECTION, DISTRIBUTEDTASK, null, + AREA + "/variablegroups", Integer.toString(groupId), null, ApiVersion.VARIABLE_GROUPS, null, requestBody); + + return MAPPER.mapJsonResponse(r, VariableGroup.class); + } + + /*** + * Helper method to convert integer array to string. + * @param i integer array + * @return {@link String} + */ + private String intArrayToString(int[] i) { + var r = Arrays.stream(i).mapToObj(String::valueOf).toArray(String[]::new); + return String.join(",", r); + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/DeploymentGroup.java b/azd/src/main/java/org/azd/distributedtask/types/DeploymentGroup.java new file mode 100644 index 00000000..6a935a01 --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/DeploymentGroup.java @@ -0,0 +1,133 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.azd.release.types.ProjectReference; + +import java.util.Arrays; +import java.util.List; + +/*** + * Deployment group. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class DeploymentGroup { + /*** + * Description of the deployment group. + */ + @JsonProperty("description") + private String description; + /*** + * Deployment group identifier. + */ + @JsonProperty("id") + private int id; + /*** + * Number of deployment targets in the deployment group. + */ + @JsonProperty("machineCount") + private int machineCount; + /*** + * List of unique tags across all deployment targets in the deployment group. + */ + @JsonProperty("machineTags") + private String[] machineTags; + /*** + * List of deployment targets in the deployment group. + */ + @JsonProperty("machines") + private List machines; + /*** + * Name of the deployment group. + */ + @JsonProperty("name") + private String name; + /*** + * Deployment pool in which deployment agents are registered. + */ + @JsonProperty("pool") + private TaskAgentPoolReference pool; + /*** + * Project to which the deployment group belongs. + */ + @JsonProperty("project") + private ProjectReference project; + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getMachineCount() { + return machineCount; + } + + public void setMachineCount(int machineCount) { + this.machineCount = machineCount; + } + + public String[] getMachineTags() { + return machineTags; + } + + public void setMachineTags(String[] machineTags) { + this.machineTags = machineTags; + } + + public List getMachines() { + return machines; + } + + public void setMachines(List machines) { + this.machines = machines; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public TaskAgentPoolReference getPool() { + return pool; + } + + public void setPool(TaskAgentPoolReference pool) { + this.pool = pool; + } + + public ProjectReference getProject() { + return project; + } + + public void setProject(ProjectReference project) { + this.project = project; + } + + @Override + public String toString() { + return "DeploymentGroup{" + + "description='" + description + '\'' + + ", id=" + id + + ", machineCount=" + machineCount + + ", machineTags=" + Arrays.toString(machineTags) + + ", machines=" + machines + + ", name='" + name + '\'' + + ", pool=" + pool + + ", project=" + project + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/DeploymentGroups.java b/azd/src/main/java/org/azd/distributedtask/types/DeploymentGroups.java new file mode 100644 index 00000000..2bb6da36 --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/DeploymentGroups.java @@ -0,0 +1,33 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +/*** + * List of deployment group + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class DeploymentGroups { + /*** + * List of deployment group + */ + @JsonProperty("value") + private List deploymentGroups; + + @Override + public String toString() { + return "DeploymentGroups{" + + "deploymentGroups=" + deploymentGroups + + '}'; + } + + public List getDeploymentGroups() { + return deploymentGroups; + } + + public void setDeploymentGroups(List deploymentGroups) { + this.deploymentGroups = deploymentGroups; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/DeploymentMachine.java b/azd/src/main/java/org/azd/distributedtask/types/DeploymentMachine.java new file mode 100644 index 00000000..7dd8d8c2 --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/DeploymentMachine.java @@ -0,0 +1,77 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; + +import java.util.Arrays; + +/*** + * Deployment target. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class DeploymentMachine { + /*** + * + * Deployment agent. + */ + @JsonProperty("agent") + private TaskAgent agent; + /*** + * Deployment target Identifier. + */ + @JsonProperty("id") + private int id; + /*** + * Properties of the deployment target. + */ + @JsonProperty("properties") + private JsonNode properties; + /*** + * Tags of the deployment target. + */ + @JsonProperty("tags") + private String[] tags; + + public TaskAgent getAgent() { + return agent; + } + + public void setAgent(TaskAgent agent) { + this.agent = agent; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public JsonNode getProperties() { + return properties; + } + + public void setProperties(JsonNode properties) { + this.properties = properties; + } + + public String[] getTags() { + return tags; + } + + public void setTags(String[] tags) { + this.tags = tags; + } + + @Override + public String toString() { + return "DeploymentMachine{" + + "agent=" + agent + + ", id=" + id + + ", properties=" + properties + + ", tags=" + Arrays.toString(tags) + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/EnvironmentInstance.java b/azd/src/main/java/org/azd/distributedtask/types/EnvironmentInstance.java new file mode 100644 index 00000000..84df4c77 --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/EnvironmentInstance.java @@ -0,0 +1,150 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.azd.common.types.Author; +import org.azd.release.types.ProjectReference; + +import java.util.List; + +/*** + * Represents an environment + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class EnvironmentInstance { + /*** + * Identity reference of the user who created the Environment. + */ + @JsonProperty("createdBy") + private Author createdBy; + /*** + * + * Creation time of the Environment + */ + @JsonProperty("createdOn") + private String createdOn; + /*** + * Description of the Environment. + */ + @JsonProperty("description") + private String description; + /*** + * + * Id of the Environment + */ + @JsonProperty("id") + private int id; + /*** + * Identity reference of the user who last modified the Environment. + */ + @JsonProperty("lastModifiedBy") + private Author lastModifiedBy; + /*** + * + * Last modified time of the Environment + */ + @JsonProperty("lastModifiedOn") + private String lastModifiedOn; + /*** + * Name of the Environment. + */ + @JsonProperty("name") + private String name; + /*** + * Project information for environment. + */ + @JsonProperty("project") + private ProjectReference project; + /*** + * EnvironmentResourceReference. + */ + @JsonProperty("resources") + private List resources; + + public Author getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(Author createdBy) { + this.createdBy = createdBy; + } + + public String getCreatedOn() { + return createdOn; + } + + public void setCreatedOn(String createdOn) { + this.createdOn = createdOn; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Author getLastModifiedBy() { + return lastModifiedBy; + } + + public void setLastModifiedBy(Author lastModifiedBy) { + this.lastModifiedBy = lastModifiedBy; + } + + public String getLastModifiedOn() { + return lastModifiedOn; + } + + public void setLastModifiedOn(String lastModifiedOn) { + this.lastModifiedOn = lastModifiedOn; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public ProjectReference getProject() { + return project; + } + + public void setProject(ProjectReference project) { + this.project = project; + } + + public List getResources() { + return resources; + } + + public void setResources(List resources) { + this.resources = resources; + } + + @Override + public String toString() { + return "EnvironmentInstance{" + + "createdBy=" + createdBy + + ", createdOn='" + createdOn + '\'' + + ", description='" + description + '\'' + + ", id=" + id + + ", lastModifiedBy=" + lastModifiedBy + + ", lastModifiedOn='" + lastModifiedOn + '\'' + + ", name='" + name + '\'' + + ", project=" + project + + ", resources=" + resources + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/EnvironmentInstances.java b/azd/src/main/java/org/azd/distributedtask/types/EnvironmentInstances.java new file mode 100644 index 00000000..1b8e8b5e --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/EnvironmentInstances.java @@ -0,0 +1,33 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +/*** + * Array of environment instance {@link EnvironmentInstance} + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class EnvironmentInstances { + /*** + * Array of environment instance {@link EnvironmentInstance} + */ + @JsonProperty("value") + private List environmentInstances; + + public List getEnvironmentInstances() { + return environmentInstances; + } + + public void setEnvironmentInstances(List environmentInstances) { + this.environmentInstances = environmentInstances; + } + + @Override + public String toString() { + return "EnvironmentInstances{" + + "environmentInstances=" + environmentInstances + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/EnvironmentResourceReference.java b/azd/src/main/java/org/azd/distributedtask/types/EnvironmentResourceReference.java new file mode 100644 index 00000000..3982c26b --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/EnvironmentResourceReference.java @@ -0,0 +1,75 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Arrays; + +/*** + * EnvironmentResourceReference. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class EnvironmentResourceReference { + /*** + * Id of the resource. + */ + @JsonProperty("id") + private int id; + /*** + * Name of the resource. + */ + @JsonProperty("name") + private String name; + /*** + * Tags of the Environment Resource Reference. + */ + @JsonProperty("tags") + private String[] tags; + /*** + * Type of the resource. + */ + @JsonProperty("type") + private String type; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String[] getTags() { + return tags; + } + + public void setTags(String[] tags) { + this.tags = tags; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @Override + public String toString() { + return "EnvironmentResourceReference{" + + "id=" + id + + ", name='" + name + '\'' + + ", tags=" + Arrays.toString(tags) + + ", type='" + type + '\'' + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/TaskAgent.java b/azd/src/main/java/org/azd/distributedtask/types/TaskAgent.java new file mode 100644 index 00000000..5f9392d9 --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/TaskAgent.java @@ -0,0 +1,286 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; + +/*** + * A task agent. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class TaskAgent { + /*** + * This agent's access point. + */ + @JsonProperty("accessPoint") + private String accessPoint; + /*** + * The agent cloud request that's currently associated with this agent. + */ + @JsonProperty("assignedAgentCloudRequest") + private TaskAgentCloudRequest assignedAgentCloudRequest; + /*** + * The request which is currently assigned to this agent. + */ + @JsonProperty("assignedRequest") + private TaskAgentJobRequest assignedRequest; + /*** + * Authorization information for this agent. + */ + @JsonProperty("authorization") + private TaskAgentAuthorization authorization; + /*** + * Date on which this agent was created. + */ + @JsonProperty("createdOn") + private String createdOn; + /*** + * Whether or not this agent should run jobs. + */ + @JsonProperty("enabled") + private boolean enabled; + /*** + * Identifier of the agent. + */ + @JsonProperty("id") + private int id; + /*** + * The last request which was completed by this agent. + */ + @JsonProperty("lastCompletedRequest") + private TaskAgentJobRequest lastCompletedRequest; + /*** + * Maximum job parallelism allowed for this agent. + */ + @JsonProperty("maxParallelism") + private int maxParallelism; + /*** + * Name of the agent. + */ + @JsonProperty("name") + private String name; + /*** + * Agent OS. + */ + @JsonProperty("osDescription") + private String osDescription; + /*** + * Pending update for this agent. + */ + @JsonProperty("pendingUpdate") + private TaskAgentUpdate pendingUpdate; + /*** + * The class represents a property bag as a collection of key-value pairs. + */ + @JsonProperty("properties") + private JsonNode properties; + /*** + * Provisioning state of this agent. + */ + @JsonProperty("provisioningState") + private String provisioningState; + /*** + * Whether or not the agent is online. + */ + @JsonProperty("status") + private String status; + /*** + * Date on which the last connectivity status change occurred. + */ + @JsonProperty("statusChangedOn") + private String statusChangedOn; + /*** + * System-defined capabilities supported by this agent's host. + * Warning: To set capabilities use the PUT method, PUT will completely overwrite existing capabilities. + */ + @JsonProperty("systemCapabilities") + private JsonNode systemCapabilities; + /*** + * User-defined capabilities supported by this agent's host. + * Warning: To set capabilities use the PUT method, PUT will completely overwrite existing capabilities. + */ + @JsonProperty("userCapabilities") + private JsonNode userCapabilities; + /*** + * Agent version. + */ + @JsonProperty("version") + private String version; + + public String getAccessPoint() { + return accessPoint; + } + + public void setAccessPoint(String accessPoint) { + this.accessPoint = accessPoint; + } + + public TaskAgentCloudRequest getAssignedAgentCloudRequest() { + return assignedAgentCloudRequest; + } + + public void setAssignedAgentCloudRequest(TaskAgentCloudRequest assignedAgentCloudRequest) { + this.assignedAgentCloudRequest = assignedAgentCloudRequest; + } + + public TaskAgentJobRequest getAssignedRequest() { + return assignedRequest; + } + + public void setAssignedRequest(TaskAgentJobRequest assignedRequest) { + this.assignedRequest = assignedRequest; + } + + public TaskAgentAuthorization getAuthorization() { + return authorization; + } + + public void setAuthorization(TaskAgentAuthorization authorization) { + this.authorization = authorization; + } + + public String getCreatedOn() { + return createdOn; + } + + public void setCreatedOn(String createdOn) { + this.createdOn = createdOn; + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public TaskAgentJobRequest getLastCompletedRequest() { + return lastCompletedRequest; + } + + public void setLastCompletedRequest(TaskAgentJobRequest lastCompletedRequest) { + this.lastCompletedRequest = lastCompletedRequest; + } + + public int getMaxParallelism() { + return maxParallelism; + } + + public void setMaxParallelism(int maxParallelism) { + this.maxParallelism = maxParallelism; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getOsDescription() { + return osDescription; + } + + public void setOsDescription(String osDescription) { + this.osDescription = osDescription; + } + + public TaskAgentUpdate getPendingUpdate() { + return pendingUpdate; + } + + public void setPendingUpdate(TaskAgentUpdate pendingUpdate) { + this.pendingUpdate = pendingUpdate; + } + + public JsonNode getProperties() { + return properties; + } + + public void setProperties(JsonNode properties) { + this.properties = properties; + } + + public String getProvisioningState() { + return provisioningState; + } + + public void setProvisioningState(String provisioningState) { + this.provisioningState = provisioningState; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatusChangedOn() { + return statusChangedOn; + } + + public void setStatusChangedOn(String statusChangedOn) { + this.statusChangedOn = statusChangedOn; + } + + public JsonNode getSystemCapabilities() { + return systemCapabilities; + } + + public void setSystemCapabilities(JsonNode systemCapabilities) { + this.systemCapabilities = systemCapabilities; + } + + public JsonNode getUserCapabilities() { + return userCapabilities; + } + + public void setUserCapabilities(JsonNode userCapabilities) { + this.userCapabilities = userCapabilities; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + @Override + public String toString() { + return "TaskAgent{" + + "accessPoint='" + accessPoint + '\'' + + ", assignedAgentCloudRequest=" + assignedAgentCloudRequest + + ", assignedRequest=" + assignedRequest + + ", authorization=" + authorization + + ", createdOn='" + createdOn + '\'' + + ", enabled=" + enabled + + ", id=" + id + + ", lastCompletedRequest=" + lastCompletedRequest + + ", maxParallelism=" + maxParallelism + + ", name='" + name + '\'' + + ", osDescription='" + osDescription + '\'' + + ", pendingUpdate=" + pendingUpdate + + ", properties=" + properties + + ", provisioningState='" + provisioningState + '\'' + + ", status='" + status + '\'' + + ", statusChangedOn='" + statusChangedOn + '\'' + + ", systemCapabilities=" + systemCapabilities + + ", userCapabilities=" + userCapabilities + + ", version='" + version + '\'' + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/TaskAgentAuthorization.java b/azd/src/main/java/org/azd/distributedtask/types/TaskAgentAuthorization.java new file mode 100644 index 00000000..967215a2 --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/TaskAgentAuthorization.java @@ -0,0 +1,59 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +/*** + * Provides data necessary for authorizing the agent using OAuth 2.0 authentication flows. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class TaskAgentAuthorization { + /*** + * Endpoint used to obtain access tokens from the configured token service. + */ + @JsonProperty("authorizationUrl") + private String authorizationUrl; + /*** + * Client identifier for this agent. + */ + @JsonProperty("clientId") + private String clientId; + /*** + * Public key used to verify the identity of this agent. + */ + @JsonProperty("publicKey") + private TaskAgentPublicKey publicKey; + + public String getAuthorizationUrl() { + return authorizationUrl; + } + + public void setAuthorizationUrl(String authorizationUrl) { + this.authorizationUrl = authorizationUrl; + } + + public String getClientId() { + return clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public TaskAgentPublicKey getPublicKey() { + return publicKey; + } + + public void setPublicKey(TaskAgentPublicKey publicKey) { + this.publicKey = publicKey; + } + + @Override + public String toString() { + return "TaskAgentAuthorization{" + + "authorizationUrl='" + authorizationUrl + '\'' + + ", clientId='" + clientId + '\'' + + ", publicKey=" + publicKey + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/TaskAgentCloudRequest.java b/azd/src/main/java/org/azd/distributedtask/types/TaskAgentCloudRequest.java new file mode 100644 index 00000000..05723567 --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/TaskAgentCloudRequest.java @@ -0,0 +1,158 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; + +/*** + * The agent cloud request that's currently associated with this agent. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class TaskAgentCloudRequest { + /*** + * A reference to an agent. + */ + @JsonProperty("agent") + private TaskAgentReference agent; + /*** + * Agent cloud id + */ + @JsonProperty("agentCloudId") + private int agentCloudId; + /*** + * Agent connected time + */ + @JsonProperty("agentConnectedTime") + private String agentConnectedTime; + /*** + * Represents a JSON object. + */ + @JsonProperty("agentData") + private JsonNode agentData; + /*** + * Represents a JSON object. + */ + @JsonProperty("agentSpecification") + private JsonNode agentSpecification; + /*** + * Task Pool reference + */ + @JsonProperty("pool") + private TaskAgentPoolReference pool; + /*** + * Provision request time + */ + @JsonProperty("provisionRequestTime") + private String provisionRequestTime; + /*** + * Provisioned time + */ + @JsonProperty("provisionedTime") + private String provisionedTime; + /*** + * Release request time + */ + @JsonProperty("releaseRequestTime") + private String releaseRequestTime; + /*** + * Request id + */ + @JsonProperty("requestId") + private String requestId; + + public TaskAgentReference getAgent() { + return agent; + } + + public void setAgent(TaskAgentReference agent) { + this.agent = agent; + } + + public int getAgentCloudId() { + return agentCloudId; + } + + public void setAgentCloudId(int agentCloudId) { + this.agentCloudId = agentCloudId; + } + + public String getAgentConnectedTime() { + return agentConnectedTime; + } + + public void setAgentConnectedTime(String agentConnectedTime) { + this.agentConnectedTime = agentConnectedTime; + } + + public JsonNode getAgentData() { + return agentData; + } + + public void setAgentData(JsonNode agentData) { + this.agentData = agentData; + } + + public JsonNode getAgentSpecification() { + return agentSpecification; + } + + public void setAgentSpecification(JsonNode agentSpecification) { + this.agentSpecification = agentSpecification; + } + + public TaskAgentPoolReference getPool() { + return pool; + } + + public void setPool(TaskAgentPoolReference pool) { + this.pool = pool; + } + + public String getProvisionRequestTime() { + return provisionRequestTime; + } + + public void setProvisionRequestTime(String provisionRequestTime) { + this.provisionRequestTime = provisionRequestTime; + } + + public String getProvisionedTime() { + return provisionedTime; + } + + public void setProvisionedTime(String provisionedTime) { + this.provisionedTime = provisionedTime; + } + + public String getReleaseRequestTime() { + return releaseRequestTime; + } + + public void setReleaseRequestTime(String releaseRequestTime) { + this.releaseRequestTime = releaseRequestTime; + } + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + @Override + public String toString() { + return "TaskAgentCloudRequest{" + + "agent=" + agent + + ", agentCloudId=" + agentCloudId + + ", agentConnectedTime='" + agentConnectedTime + '\'' + + ", agentData=" + agentData + + ", agentSpecification=" + agentSpecification + + ", pool=" + pool + + ", provisionRequestTime='" + provisionRequestTime + '\'' + + ", provisionedTime='" + provisionedTime + '\'' + + ", releaseRequestTime='" + releaseRequestTime + '\'' + + ", requestId='" + requestId + '\'' + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/TaskAgentJobRequest.java b/azd/src/main/java/org/azd/distributedtask/types/TaskAgentJobRequest.java new file mode 100644 index 00000000..8806168f --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/TaskAgentJobRequest.java @@ -0,0 +1,427 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; +import org.azd.build.types.Demand; + +import java.util.List; + +/*** + * A job request for an agent. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class TaskAgentJobRequest { + /*** + * Represents a JSON object. + */ + @JsonProperty("agentSpecification") + private JsonNode agentSpecification; + /*** + * The date/time this request was assigned. + */ + @JsonProperty("assignTime") + private String assignTime; + /*** + * Additional data about the request. + */ + @JsonProperty("data") + private JsonNode data; + /*** + * The pipeline definition associated with this request + */ + @JsonProperty("definition") + private TaskOrchestrationOwner definition; + /*** + * A list of demands required to fulfill this request. + */ + @JsonProperty("demands") + private List demands; + /*** + * The date/time this request was finished. + */ + @JsonProperty("finishTime") + private String finishTime; + /*** + * The host which triggered this request. + */ + @JsonProperty("hostId") + private String hostId; + /*** + * ID of the job resulting from this request. + */ + @JsonProperty("jobId") + private String jobId; + /*** + * Name of the job resulting from this request. + */ + @JsonProperty("jobName") + private String jobName; + /*** + * The deadline for the agent to renew the lock. + */ + @JsonProperty("lockedUntil") + private String lockedUntil; + /*** + * A reference to an agent. + */ + @JsonProperty("matchedAgents") + private TaskAgentReference matchedAgents; + /*** + * Matches all agents in pool + */ + @JsonProperty("matchesAllAgentsInPool") + private boolean matchesAllAgentsInPool; + /*** + * Orchestration id + */ + @JsonProperty("orchestrationId") + private String orchestrationId; + /*** + * The pipeline associated with this request + */ + @JsonProperty("owner") + private TaskOrchestrationOwner owner; + /*** + * Plan group + */ + @JsonProperty("planGroup") + private String planGroup; + /*** + * Internal ID for the orchestration plan connected with this request. + */ + @JsonProperty("planId") + private String planId; + /*** + * Internal detail representing the type of orchestration plan. + */ + @JsonProperty("planType") + private String planType; + /*** + * The ID of the pool this request targets + */ + @JsonProperty("poolId") + private int poolId; + /*** + * Priority + */ + @JsonProperty("priority") + private int priority; + /*** + * The ID of the queue this request targets + */ + @JsonProperty("queueId") + private int queueId; + /*** + * The date/time this request was queued. + */ + @JsonProperty("queueTime") + private String queueTime; + /*** + * The date/time this request was received by an agent. + */ + @JsonProperty("receiveTime") + private String receiveTime; + /*** + * ID of the request. + */ + @JsonProperty("requestId") + private int requestId; + /*** + * The agent allocated for this request. + */ + @JsonProperty("reservedAgent") + private TaskAgentReference reservedAgent; + /*** + * The result of this request. + */ + @JsonProperty("result") + private String result; + /*** + * Scope of the pipeline; matches the project ID. + */ + @JsonProperty("scopeId") + private String scopeId; + /*** + * The service which owns this request. + */ + @JsonProperty("serviceOwner") + private String serviceOwner; + /*** + * Status message + */ + @JsonProperty("statusMessage") + private String statusMessage; + /*** + * user delayed + */ + @JsonProperty("userDelayed") + private boolean userDelayed; + + public JsonNode getAgentSpecification() { + return agentSpecification; + } + + public void setAgentSpecification(JsonNode agentSpecification) { + this.agentSpecification = agentSpecification; + } + + public String getAssignTime() { + return assignTime; + } + + public void setAssignTime(String assignTime) { + this.assignTime = assignTime; + } + + public JsonNode getData() { + return data; + } + + public void setData(JsonNode data) { + this.data = data; + } + + public TaskOrchestrationOwner getDefinition() { + return definition; + } + + public void setDefinition(TaskOrchestrationOwner definition) { + this.definition = definition; + } + + public List getDemands() { + return demands; + } + + public void setDemands(List demands) { + this.demands = demands; + } + + public String getFinishTime() { + return finishTime; + } + + public void setFinishTime(String finishTime) { + this.finishTime = finishTime; + } + + public String getHostId() { + return hostId; + } + + public void setHostId(String hostId) { + this.hostId = hostId; + } + + public String getJobId() { + return jobId; + } + + public void setJobId(String jobId) { + this.jobId = jobId; + } + + public String getJobName() { + return jobName; + } + + public void setJobName(String jobName) { + this.jobName = jobName; + } + + public String getLockedUntil() { + return lockedUntil; + } + + public void setLockedUntil(String lockedUntil) { + this.lockedUntil = lockedUntil; + } + + public TaskAgentReference getMatchedAgents() { + return matchedAgents; + } + + public void setMatchedAgents(TaskAgentReference matchedAgents) { + this.matchedAgents = matchedAgents; + } + + public boolean isMatchesAllAgentsInPool() { + return matchesAllAgentsInPool; + } + + public void setMatchesAllAgentsInPool(boolean matchesAllAgentsInPool) { + this.matchesAllAgentsInPool = matchesAllAgentsInPool; + } + + public String getOrchestrationId() { + return orchestrationId; + } + + public void setOrchestrationId(String orchestrationId) { + this.orchestrationId = orchestrationId; + } + + public TaskOrchestrationOwner getOwner() { + return owner; + } + + public void setOwner(TaskOrchestrationOwner owner) { + this.owner = owner; + } + + public String getPlanGroup() { + return planGroup; + } + + public void setPlanGroup(String planGroup) { + this.planGroup = planGroup; + } + + public String getPlanId() { + return planId; + } + + public void setPlanId(String planId) { + this.planId = planId; + } + + public String getPlanType() { + return planType; + } + + public void setPlanType(String planType) { + this.planType = planType; + } + + public int getPoolId() { + return poolId; + } + + public void setPoolId(int poolId) { + this.poolId = poolId; + } + + public int getPriority() { + return priority; + } + + public void setPriority(int priority) { + this.priority = priority; + } + + public int getQueueId() { + return queueId; + } + + public void setQueueId(int queueId) { + this.queueId = queueId; + } + + public String getQueueTime() { + return queueTime; + } + + public void setQueueTime(String queueTime) { + this.queueTime = queueTime; + } + + public String getReceiveTime() { + return receiveTime; + } + + public void setReceiveTime(String receiveTime) { + this.receiveTime = receiveTime; + } + + public int getRequestId() { + return requestId; + } + + public void setRequestId(int requestId) { + this.requestId = requestId; + } + + public TaskAgentReference getReservedAgent() { + return reservedAgent; + } + + public void setReservedAgent(TaskAgentReference reservedAgent) { + this.reservedAgent = reservedAgent; + } + + public String getResult() { + return result; + } + + public void setResult(String result) { + this.result = result; + } + + public String getScopeId() { + return scopeId; + } + + public void setScopeId(String scopeId) { + this.scopeId = scopeId; + } + + public String getServiceOwner() { + return serviceOwner; + } + + public void setServiceOwner(String serviceOwner) { + this.serviceOwner = serviceOwner; + } + + public String getStatusMessage() { + return statusMessage; + } + + public void setStatusMessage(String statusMessage) { + this.statusMessage = statusMessage; + } + + public boolean isUserDelayed() { + return userDelayed; + } + + public void setUserDelayed(boolean userDelayed) { + this.userDelayed = userDelayed; + } + + @Override + public String toString() { + return "TaskAgentJobRequest{" + + "agentSpecification=" + agentSpecification + + ", assignTime='" + assignTime + '\'' + + ", data=" + data + + ", definition=" + definition + + ", demands=" + demands + + ", finishTime='" + finishTime + '\'' + + ", hostId='" + hostId + '\'' + + ", jobId='" + jobId + '\'' + + ", jobName='" + jobName + '\'' + + ", lockedUntil='" + lockedUntil + '\'' + + ", matchedAgents=" + matchedAgents + + ", matchesAllAgentsInPool=" + matchesAllAgentsInPool + + ", orchestrationId='" + orchestrationId + '\'' + + ", owner=" + owner + + ", planGroup='" + planGroup + '\'' + + ", planId='" + planId + '\'' + + ", planType='" + planType + '\'' + + ", poolId=" + poolId + + ", priority=" + priority + + ", queueId=" + queueId + + ", queueTime='" + queueTime + '\'' + + ", receiveTime='" + receiveTime + '\'' + + ", requestId=" + requestId + + ", reservedAgent=" + reservedAgent + + ", result='" + result + '\'' + + ", scopeId='" + scopeId + '\'' + + ", serviceOwner='" + serviceOwner + '\'' + + ", statusMessage='" + statusMessage + '\'' + + ", userDelayed=" + userDelayed + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/TaskAgentPoolReference.java b/azd/src/main/java/org/azd/distributedtask/types/TaskAgentPoolReference.java new file mode 100644 index 00000000..1cd04069 --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/TaskAgentPoolReference.java @@ -0,0 +1,129 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +/*** + * Task agent pool reference + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class TaskAgentPoolReference { + /*** + * Id of the pool + */ + @JsonProperty("id") + private int id; + /*** + * Gets or sets a value indicating whether or not this pool is managed by the service. + */ + @JsonProperty("isHosted") + private boolean isHosted; + /*** + * Determines whether the pool is legacy. + */ + @JsonProperty("isLegacy") + private boolean isLegacy; + /*** + * Name of the agent + */ + @JsonProperty("name") + private String name; + /*** + * Additional pool settings and details + */ + @JsonProperty("options") + private String options; + /*** + * Gets or sets the type of the pool + */ + @JsonProperty("poolType") + private String poolType; + /*** + * Scope of the agent pool + */ + @JsonProperty("scope") + private String scope; + /*** + * Gets the current size of the pool. + */ + @JsonProperty("size") + private int size; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public boolean isHosted() { + return isHosted; + } + + public void setHosted(boolean hosted) { + isHosted = hosted; + } + + public boolean isLegacy() { + return isLegacy; + } + + public void setLegacy(boolean legacy) { + isLegacy = legacy; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getOptions() { + return options; + } + + public void setOptions(String options) { + this.options = options; + } + + public String getPoolType() { + return poolType; + } + + public void setPoolType(String poolType) { + this.poolType = poolType; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + @Override + public String toString() { + return "TaskAgentPoolReference{" + + "id=" + id + + ", isHosted=" + isHosted + + ", isLegacy=" + isLegacy + + ", name='" + name + '\'' + + ", options='" + options + '\'' + + ", poolType='" + poolType + '\'' + + ", scope='" + scope + '\'' + + ", size=" + size + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/TaskAgentPublicKey.java b/azd/src/main/java/org/azd/distributedtask/types/TaskAgentPublicKey.java new file mode 100644 index 00000000..9c473898 --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/TaskAgentPublicKey.java @@ -0,0 +1,47 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Arrays; + +/*** + * Represents the public key portion of an RSA asymmetric key. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class TaskAgentPublicKey { + /*** + * Gets or sets the exponent for the public key. + */ + @JsonProperty("exponent") + private String[] exponent; + /*** + * Gets or sets the modulus for the public key. + */ + @JsonProperty("modulus") + private String[] modulus; + + public String[] getExponent() { + return exponent; + } + + public void setExponent(String[] exponent) { + this.exponent = exponent; + } + + public String[] getModulus() { + return modulus; + } + + public void setModulus(String[] modulus) { + this.modulus = modulus; + } + + @Override + public String toString() { + return "TaskAgentPublicKey{" + + "exponent=" + Arrays.toString(exponent) + + ", modulus=" + Arrays.toString(modulus) + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/TaskAgentReference.java b/azd/src/main/java/org/azd/distributedtask/types/TaskAgentReference.java new file mode 100644 index 00000000..44bf7b54 --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/TaskAgentReference.java @@ -0,0 +1,129 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +/*** + * A reference to an agent. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class TaskAgentReference { + /*** + * This agent's access point. + */ + @JsonProperty("accessPoint") + private String accessPoint; + /*** + * Whether or not this agent should run jobs. + */ + @JsonProperty("enabled") + private boolean enabled; + /*** + * Identifier of the agent. + */ + @JsonProperty("id") + private int id; + /*** + * Name of the agent. + */ + @JsonProperty("name") + private String name; + /*** + * Agent OS. + */ + @JsonProperty("osDescription") + private String osDescription; + /*** + * Provisioning state of this agent. + */ + @JsonProperty("provisioningState") + private String provisioningState; + /*** + * Whether or not the agent is online. + */ + @JsonProperty("status") + private String status; + /*** + * Agent version. + */ + @JsonProperty("version") + private String version; + + public String getAccessPoint() { + return accessPoint; + } + + public void setAccessPoint(String accessPoint) { + this.accessPoint = accessPoint; + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getOsDescription() { + return osDescription; + } + + public void setOsDescription(String osDescription) { + this.osDescription = osDescription; + } + + public String getProvisioningState() { + return provisioningState; + } + + public void setProvisioningState(String provisioningState) { + this.provisioningState = provisioningState; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + @Override + public String toString() { + return "TaskAgentReference{" + + "accessPoint='" + accessPoint + '\'' + + ", enabled=" + enabled + + ", id=" + id + + ", name='" + name + '\'' + + ", osDescription='" + osDescription + '\'' + + ", provisioningState='" + provisioningState + '\'' + + ", status='" + status + '\'' + + ", version='" + version + '\'' + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/TaskAgentUpdate.java b/azd/src/main/java/org/azd/distributedtask/types/TaskAgentUpdate.java new file mode 100644 index 00000000..983237ac --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/TaskAgentUpdate.java @@ -0,0 +1,102 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.azd.common.types.Author; + +/*** + * Details about an agent update. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class TaskAgentUpdate { + /*** + * Current state of this agent update. + */ + @JsonProperty("currentState") + private String currentState; + /*** + * Reason for this update. + */ + @JsonProperty("reason") + private TaskAgentUpdateReason reason; + /*** + * Date on which this update was requested. + */ + @JsonProperty("requestTime") + private String requestTime; + /*** + * Identity which requested this update. + */ + @JsonProperty("requestedBy") + private Author requestedBy; + /*** + * Source agent version of the update. + */ + @JsonProperty("sourceVersion") + private int sourceVersion; + /*** + * Target agent version of the update. + */ + @JsonProperty("targetVersion") + private int targetVersion; + + public String getCurrentState() { + return currentState; + } + + public void setCurrentState(String currentState) { + this.currentState = currentState; + } + + public TaskAgentUpdateReason getReason() { + return reason; + } + + public void setReason(TaskAgentUpdateReason reason) { + this.reason = reason; + } + + public String getRequestTime() { + return requestTime; + } + + public void setRequestTime(String requestTime) { + this.requestTime = requestTime; + } + + public Author getRequestedBy() { + return requestedBy; + } + + public void setRequestedBy(Author requestedBy) { + this.requestedBy = requestedBy; + } + + public int getSourceVersion() { + return sourceVersion; + } + + public void setSourceVersion(int sourceVersion) { + this.sourceVersion = sourceVersion; + } + + public int getTargetVersion() { + return targetVersion; + } + + public void setTargetVersion(int targetVersion) { + this.targetVersion = targetVersion; + } + + @Override + public String toString() { + return "TaskAgentUpdate{" + + "currentState='" + currentState + '\'' + + ", reason=" + reason + + ", requestTime='" + requestTime + '\'' + + ", requestedBy=" + requestedBy + + ", sourceVersion=" + sourceVersion + + ", targetVersion=" + targetVersion + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/TaskAgentUpdateReason.java b/azd/src/main/java/org/azd/distributedtask/types/TaskAgentUpdateReason.java new file mode 100644 index 00000000..f76b72a9 --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/TaskAgentUpdateReason.java @@ -0,0 +1,31 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +/*** + * Reason for this update. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class TaskAgentUpdateReason { + /*** + * Code + */ + @JsonProperty("code") + private String code; + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + @Override + public String toString() { + return "TaskAgentUpdateReason{" + + "code='" + code + '\'' + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/TaskAgents.java b/azd/src/main/java/org/azd/distributedtask/types/TaskAgents.java new file mode 100644 index 00000000..9633d99a --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/TaskAgents.java @@ -0,0 +1,33 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +/*** + * List of task agent + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class TaskAgents { + /*** + * List of task agent + */ + @JsonProperty("value") + private List taskAgents; + + public List getTaskAgents() { + return taskAgents; + } + + public void setTaskAgents(List taskAgents) { + this.taskAgents = taskAgents; + } + + @Override + public String toString() { + return "TaskAgents{" + + "taskAgents=" + taskAgents + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/TaskOrchestrationOwner.java b/azd/src/main/java/org/azd/distributedtask/types/TaskOrchestrationOwner.java new file mode 100644 index 00000000..83b3afe8 --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/TaskOrchestrationOwner.java @@ -0,0 +1,45 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +/*** + * The pipeline associated with this request + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class TaskOrchestrationOwner { + /*** + * Id of the pipeline + */ + @JsonProperty("id") + private int id; + /*** + * Name of the pipeline + */ + @JsonProperty("name") + private String name; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "TaskOrchestrationOwner{" + + "id=" + id + + ", name='" + name + '\'' + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/VariableGroup.java b/azd/src/main/java/org/azd/distributedtask/types/VariableGroup.java new file mode 100644 index 00000000..e3295df8 --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/VariableGroup.java @@ -0,0 +1,189 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; +import org.azd.common.types.Author; + +import java.util.List; + +/*** + * A variable group is a collection of related variables. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class VariableGroup { + /*** + * Gets or sets the identity who created the variable group. + */ + @JsonProperty("createdBy") + private Author createdBy; + /*** + * Gets or sets the time when variable group was created. + */ + @JsonProperty("createdOn") + private String createdOn; + /*** + * Gets or sets description of the variable group. + */ + @JsonProperty("description") + private String description; + /*** + * Gets or sets id of the variable group. + */ + @JsonProperty("id") + private int id; + /*** + * Indicates whether variable group is shared with other projects or not. + */ + @JsonProperty("isShared") + private boolean isShared; + /*** + * Gets or sets the identity who modified the variable group. + */ + @JsonProperty("modifiedBy") + private Author modifiedBy; + /*** + * Gets or sets the time when variable group was modified + */ + @JsonProperty("modifiedOn") + private String modifiedOn; + /*** + * Gets or sets name of the variable group. + */ + @JsonProperty("name") + private String name; + /*** + * Gets or sets provider data. + */ + @JsonProperty("providerData") + private JsonNode providerData; + /*** + * Gets or sets type of the variable group. + */ + @JsonProperty("type") + private String type; + /*** + * all project references where the variable group is shared with other projects. + */ + @JsonProperty("variableGroupProjectReferences") + private List variableGroupProjectReferences; + /*** + * Gets or sets variables contained in the variable group. + */ + @JsonProperty("variables") + private JsonNode variables; + + public Author getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(Author createdBy) { + this.createdBy = createdBy; + } + + public String getCreatedOn() { + return createdOn; + } + + public void setCreatedOn(String createdOn) { + this.createdOn = createdOn; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public boolean isShared() { + return isShared; + } + + public void setShared(boolean shared) { + isShared = shared; + } + + public Author getModifiedBy() { + return modifiedBy; + } + + public void setModifiedBy(Author modifiedBy) { + this.modifiedBy = modifiedBy; + } + + public String getModifiedOn() { + return modifiedOn; + } + + public void setModifiedOn(String modifiedOn) { + this.modifiedOn = modifiedOn; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public JsonNode getProviderData() { + return providerData; + } + + public void setProviderData(JsonNode providerData) { + this.providerData = providerData; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public List getVariableGroupProjectReferences() { + return variableGroupProjectReferences; + } + + public void setVariableGroupProjectReferences(List variableGroupProjectReferences) { + this.variableGroupProjectReferences = variableGroupProjectReferences; + } + + public JsonNode getVariables() { + return variables; + } + + public void setVariables(JsonNode variables) { + this.variables = variables; + } + + @Override + public String toString() { + return "VariableGroup{" + + "createdBy=" + createdBy + + ", createdOn='" + createdOn + '\'' + + ", description='" + description + '\'' + + ", id=" + id + + ", isShared=" + isShared + + ", modifiedBy=" + modifiedBy + + ", modifiedOn='" + modifiedOn + '\'' + + ", name='" + name + '\'' + + ", providerData=" + providerData + + ", type='" + type + '\'' + + ", variableGroupProjectReferences=" + variableGroupProjectReferences + + ", variables=" + variables + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/VariableGroupDefinition.java b/azd/src/main/java/org/azd/distributedtask/types/VariableGroupDefinition.java new file mode 100644 index 00000000..86f4ef58 --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/VariableGroupDefinition.java @@ -0,0 +1,96 @@ +package org.azd.distributedtask.types; + +import org.azd.enums.VariableGroupType; +import org.azd.release.types.ProjectReference; + +import java.util.Map; + +/*** + * Represents the request body for adding and updating a variable group. + */ +public class VariableGroupDefinition { + /*** + * Sets name of the variable group. + */ + private String name; + /*** + * Sets description of the variable group. + */ + private String description; + /*** + * Sets type of the variable group. + */ + private VariableGroupType type; + /*** + * Sets variables contained in the variable group. + */ + private Map variables; + /*** + * Sets provider data. + */ + private VariableGroupProviderData providerData; + /*** + * A shallow reference of project. + */ + private ProjectReference projectReference; + + public ProjectReference getProjectReference() { + return projectReference; + } + + public void setProjectReference(ProjectReference projectReference) { + this.projectReference = projectReference; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public VariableGroupType getType() { + return type; + } + + public void setType(VariableGroupType type) { + this.type = type; + } + + public Map getVariables() { + return variables; + } + + public void setVariables(Map variables) { + this.variables = variables; + } + + public VariableGroupProviderData getProviderData() { + return providerData; + } + + public void setProviderData(VariableGroupProviderData providerData) { + this.providerData = providerData; + } + + @Override + public String toString() { + return "VariableGroupDefinition{" + + "name='" + name + '\'' + + ", description='" + description + '\'' + + ", type=" + type + + ", variables=" + variables + + ", providerData=" + providerData + + ", projectReference=" + projectReference + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/VariableGroupProjectReference.java b/azd/src/main/java/org/azd/distributedtask/types/VariableGroupProjectReference.java new file mode 100644 index 00000000..619a01ab --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/VariableGroupProjectReference.java @@ -0,0 +1,60 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.azd.release.types.ProjectReference; + +/*** + * A variable group reference is a shallow reference to variable group. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class VariableGroupProjectReference { + /*** + * Gets or sets description of the variable group. + */ + @JsonProperty("description") + private String description; + /*** + * Gets or sets name of the variable group. + */ + @JsonProperty("name") + private String name; + /*** + * Gets or sets project reference of the variable group. + */ + @JsonProperty("projectReference") + private ProjectReference projectReference; + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public ProjectReference getProjectReference() { + return projectReference; + } + + public void setProjectReference(ProjectReference projectReference) { + this.projectReference = projectReference; + } + + @Override + public String toString() { + return "VariableGroupProjectReferences{" + + "description='" + description + '\'' + + ", name='" + name + '\'' + + ", projectReference=" + projectReference + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/VariableGroupProviderData.java b/azd/src/main/java/org/azd/distributedtask/types/VariableGroupProviderData.java new file mode 100644 index 00000000..02b428e4 --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/VariableGroupProviderData.java @@ -0,0 +1,39 @@ +package org.azd.distributedtask.types; + +/*** + * Sets provider data. + */ +public class VariableGroupProviderData { + /*** + * Azure resource manager service endpoint id. + */ + private String serviceEndpointId; + /*** + * Azure key vault reference + */ + private String vault; + + public String getServiceEndpointId() { + return serviceEndpointId; + } + + public void setServiceEndpointId(String serviceEndpointId) { + this.serviceEndpointId = serviceEndpointId; + } + + public String getVault() { + return vault; + } + + public void setVault(String vault) { + this.vault = vault; + } + + @Override + public String toString() { + return "VariableGroupProviderData{" + + "serviceEndpointId='" + serviceEndpointId + '\'' + + ", vault='" + vault + '\'' + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/distributedtask/types/VariableGroups.java b/azd/src/main/java/org/azd/distributedtask/types/VariableGroups.java new file mode 100644 index 00000000..ee2e6bae --- /dev/null +++ b/azd/src/main/java/org/azd/distributedtask/types/VariableGroups.java @@ -0,0 +1,33 @@ +package org.azd.distributedtask.types; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +/** + * Container of Variable groups + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class VariableGroups { + /** + * Container of Variable groups + */ + @JsonProperty("value") + private List variableGroups; + + public List getVariableGroups() { + return variableGroups; + } + + public void setVariableGroups(List variableGroups) { + this.variableGroups = variableGroups; + } + + @Override + public String toString() { + return "VariableGroups{" + + "variableGroups=" + variableGroups + + '}'; + } +} diff --git a/azd/src/main/java/org/azd/enums/DeploymentGroupActionFilter.java b/azd/src/main/java/org/azd/enums/DeploymentGroupActionFilter.java new file mode 100644 index 00000000..afa90426 --- /dev/null +++ b/azd/src/main/java/org/azd/enums/DeploymentGroupActionFilter.java @@ -0,0 +1,16 @@ +package org.azd.enums; + +/*** + * Get the deployment group only if this action can be performed on it. + */ +public enum DeploymentGroupActionFilter { + /*** + * Only deployment groups for which caller has manage permission. + */ + MANAGE, + + /*** + * Only deployment groups for which caller has use permission. + */ + USE +} diff --git a/azd/src/main/java/org/azd/enums/DeploymentGroupExpands.java b/azd/src/main/java/org/azd/enums/DeploymentGroupExpands.java new file mode 100644 index 00000000..234bee0a --- /dev/null +++ b/azd/src/main/java/org/azd/enums/DeploymentGroupExpands.java @@ -0,0 +1,11 @@ +package org.azd.enums; + +/*** + * Include these additional details in the returned object. + */ +public enum DeploymentGroupExpands { + /*** + * Include unique list of tags across all deployment targets. + */ + TAGS +} diff --git a/azd/src/main/java/org/azd/enums/EnvironmentExpands.java b/azd/src/main/java/org/azd/enums/EnvironmentExpands.java new file mode 100644 index 00000000..1956822a --- /dev/null +++ b/azd/src/main/java/org/azd/enums/EnvironmentExpands.java @@ -0,0 +1,17 @@ +package org.azd.enums; + +/*** + * Include these additional details in the returned objects. + */ +public enum EnvironmentExpands { + /*** + * Include resource references referring to the environment. + */ + RESOURCEREFERENCES, + + /*** + * No additional properties + */ + NONE + +} diff --git a/azd/src/main/java/org/azd/enums/VariableGroupActionFilter.java b/azd/src/main/java/org/azd/enums/VariableGroupActionFilter.java new file mode 100644 index 00000000..5fb7ff78 --- /dev/null +++ b/azd/src/main/java/org/azd/enums/VariableGroupActionFilter.java @@ -0,0 +1,10 @@ +package org.azd.enums; + +/*** + * Action filter for the variable group. It specifies the action which can be performed on the variable groups. + */ +public enum VariableGroupActionFilter { + MANAGE, + NONE, + USE +} diff --git a/azd/src/main/java/org/azd/enums/VariableGroupQueryOrder.java b/azd/src/main/java/org/azd/enums/VariableGroupQueryOrder.java new file mode 100644 index 00000000..599cbf76 --- /dev/null +++ b/azd/src/main/java/org/azd/enums/VariableGroupQueryOrder.java @@ -0,0 +1,16 @@ +package org.azd.enums; + +/*** + * Gets the results in the defined order. Default is 'IdDescending'. + */ +public enum VariableGroupQueryOrder { + /*** + * Order by id ascending. + */ + IDASCENDING, + + /*** + * Order by id descending. + */ + IDDESCENDING +} diff --git a/azd/src/main/java/org/azd/enums/VariableGroupType.java b/azd/src/main/java/org/azd/enums/VariableGroupType.java new file mode 100644 index 00000000..93df6e35 --- /dev/null +++ b/azd/src/main/java/org/azd/enums/VariableGroupType.java @@ -0,0 +1,13 @@ +package org.azd.enums; + +public enum VariableGroupType { + /*** + * For creating variable group of type Vsts. This is for linking the variable groups in CI/CD pipelines. + */ + Vsts, + + /*** + * For linking azure key vault + */ + AzureKeyVault +} diff --git a/azd/src/main/java/org/azd/interfaces/AzDClient.java b/azd/src/main/java/org/azd/interfaces/AzDClient.java index ae1a5c77..aa238576 100644 --- a/azd/src/main/java/org/azd/interfaces/AzDClient.java +++ b/azd/src/main/java/org/azd/interfaces/AzDClient.java @@ -3,6 +3,7 @@ import org.azd.accounts.AccountsApi; import org.azd.build.BuildApi; import org.azd.core.CoreApi; +import org.azd.distributedtask.DistributedTaskApi; import org.azd.extensionmanagement.ExtensionManagementApi; import org.azd.feedmanagement.FeedManagementApi; import org.azd.git.GitApi; @@ -22,6 +23,7 @@ public interface AzDClient { AccountsApi getAccountsApi(); BuildApi getBuildApi(); CoreApi getCoreApi(); + DistributedTaskApi getDistributedTaskApi(); FeedManagementApi getFeedManagementApi(); GitApi getGitApi(); GraphApi getGraphApi(); diff --git a/azd/src/main/java/org/azd/interfaces/DistributedTaskDetails.java b/azd/src/main/java/org/azd/interfaces/DistributedTaskDetails.java new file mode 100644 index 00000000..96765a2b --- /dev/null +++ b/azd/src/main/java/org/azd/interfaces/DistributedTaskDetails.java @@ -0,0 +1,54 @@ +package org.azd.interfaces; + +import org.azd.distributedtask.types.*; +import org.azd.enums.*; +import org.azd.exceptions.AzDException; +import org.azd.exceptions.ConnectionException; + +import java.util.Map; + +public interface DistributedTaskDetails { + void deleteAgent(int poolId, int agentId) throws ConnectionException, AzDException; + TaskAgent getAgent(int poolId, int agentId) throws ConnectionException, AzDException; + TaskAgent getAgent(int poolId, int agentId, boolean includeAssignedRequest, boolean includeCapabilities, + boolean includeLastCompletedRequest, String[] propertyFilters) throws ConnectionException, AzDException; + TaskAgents getAgents(int poolId) throws ConnectionException, AzDException; + TaskAgents getAgents(int poolId, String agentName, String[] demands, boolean includeAssignedRequest, boolean includeCapabilities, + boolean includeLastCompletedRequest, String[] propertyFilters) throws ConnectionException, AzDException; + TaskAgent updateAgent(int poolId, int agentId, Map requestBody) throws ConnectionException, AzDException; + DeploymentGroup addDeploymentGroup(String name, String description) throws ConnectionException, AzDException; + DeploymentGroup addDeploymentGroup(String name, String description, int poolId) throws ConnectionException, AzDException; + void deleteDeploymentGroup(int deploymentGroupId) throws ConnectionException, AzDException; + DeploymentGroup getDeploymentGroup(int deploymentGroupId) throws ConnectionException, AzDException; + DeploymentGroup getDeploymentGroup(int deploymentGroupId, DeploymentGroupExpands expand, DeploymentGroupActionFilter actionFilter) + throws ConnectionException, AzDException; + DeploymentGroups getDeploymentGroups() throws ConnectionException, AzDException; + DeploymentGroups getDeploymentGroups(int top) throws ConnectionException, AzDException; + DeploymentGroups getDeploymentGroups(int[] ids) throws ConnectionException, AzDException; + DeploymentGroups getDeploymentGroups(String name) throws ConnectionException, AzDException; + DeploymentGroups getDeploymentGroups(DeploymentGroupExpands expand) throws ConnectionException, AzDException; + DeploymentGroups getDeploymentGroups(DeploymentGroupExpands expand, int top, DeploymentGroupActionFilter actionFilter, + String continuationToken, int[] ids, String name) + throws ConnectionException, AzDException; + DeploymentGroup updateDeploymentGroup(int deploymentGroupId, String name, String description) throws ConnectionException, AzDException; + EnvironmentInstance addEnvironment(String name, String description) throws ConnectionException, AzDException; + void deleteEnvironment(int environmentId) throws ConnectionException, AzDException; + EnvironmentInstance getEnvironment(int environmentId) throws ConnectionException, AzDException; + EnvironmentInstance getEnvironment(int environmentId, EnvironmentExpands expands) throws ConnectionException, AzDException; + EnvironmentInstances getEnvironments() throws ConnectionException, AzDException; + EnvironmentInstances getEnvironments(int top) throws ConnectionException, AzDException; + EnvironmentInstances getEnvironments(String name) throws ConnectionException, AzDException; + EnvironmentInstances getEnvironments(int top, String continuationToken, String name) throws ConnectionException, AzDException; + EnvironmentInstance updateEnvironment(int environmentId, String name, String description) throws ConnectionException, AzDException; + VariableGroup addVariableGroup(VariableGroupDefinition variableGroupDefinition) throws ConnectionException, AzDException; + VariableGroup addVariableGroup(String name, String description, Map variables) throws ConnectionException, AzDException; + void deleteVariableGroup(int variableGroupId, String[] projectIds) throws ConnectionException, AzDException; + VariableGroup getVariableGroup(int variableGroupId) throws ConnectionException, AzDException; + VariableGroups getVariableGroups() throws ConnectionException, AzDException; + VariableGroups getVariableGroups(int top) throws ConnectionException, AzDException; + VariableGroups getVariableGroups(String groupName) throws ConnectionException, AzDException; + VariableGroups getVariableGroups(int top, VariableGroupActionFilter actionFilter, int continuationToken, + String groupName, VariableGroupQueryOrder queryOrder) throws ConnectionException, AzDException; + VariableGroup updateVariableGroup(int groupId, String name, String description, Map variables) throws ConnectionException, AzDException; + VariableGroup updateVariableGroup(int groupId, VariableGroupDefinition variableGroupDefinition) throws ConnectionException, AzDException; +} diff --git a/azd/src/main/java/org/azd/utils/AzDClientApi.java b/azd/src/main/java/org/azd/utils/AzDClientApi.java index d34d0573..51c0d5da 100644 --- a/azd/src/main/java/org/azd/utils/AzDClientApi.java +++ b/azd/src/main/java/org/azd/utils/AzDClientApi.java @@ -4,6 +4,7 @@ import org.azd.build.BuildApi; import org.azd.connection.Connection; import org.azd.core.CoreApi; +import org.azd.distributedtask.DistributedTaskApi; import org.azd.extensionmanagement.ExtensionManagementApi; import org.azd.feedmanagement.FeedManagementApi; import org.azd.git.GitApi; @@ -108,6 +109,14 @@ public CoreApi getCoreApi() { return new CoreApi(CONNECTION); } + /*** + * Returns an instance of DistributedTask Api + * @return instance of DistributedTaskApi {@link DistributedTaskApi} + */ + + @Override + public DistributedTaskApi getDistributedTaskApi() { return new DistributedTaskApi(CONNECTION); } + /*** * Returns an instance of FeedManagement Api * @return instance of Feed management Api {@link FeedManagementApi} diff --git a/azd/src/test/java/org/azd/BuildApiTest.java b/azd/src/test/java/org/azd/BuildApiTest.java index 6d06bb18..2df55698 100644 --- a/azd/src/test/java/org/azd/BuildApiTest.java +++ b/azd/src/test/java/org/azd/BuildApiTest.java @@ -167,13 +167,13 @@ public void shouldRestoreBuildDefinition() throws ConnectionException, AzDExcept @Test public void shouldAddABuildTag() throws ConnectionException, AzDException { - b.addBuildTag(503, "Demo"); + b.addBuildTag(523, "Demo"); } @Test public void shouldAddBuildTags() throws ConnectionException, AzDException { - b.addBuildTags(503, new String[]{ "Demo", "CI", "Test" }); + b.addBuildTags(523, new String[]{ "Demo", "CI", "Test" }); } @@ -189,7 +189,7 @@ public void shouldAddDefinitionTags() throws ConnectionException, AzDException { @Test public void shouldDeleteABuildTag() throws ConnectionException, AzDException { - b.deleteBuildTag(503, "Test"); + b.deleteBuildTag(523, "Test"); } @Test @@ -204,7 +204,7 @@ public void shouldDeleteATag() throws ConnectionException, AzDException { @Test public void shouldGetBuildTags() throws ConnectionException, AzDException { - b.getBuildTags(503); + b.getBuildTags(523); } @Test @@ -219,7 +219,7 @@ public void shouldGetTags() throws ConnectionException, AzDException { @Test public void shouldUpdateBuildTags() throws ConnectionException, AzDException { - b.updateBuildTags(503, new String[]{ "Demo", "CI", "Test" }, false); + b.updateBuildTags(523, new String[]{ "Demo", "CI", "Test" }, false); } @Test diff --git a/azd/src/test/java/org/azd/DistributedTaskApiTest.java b/azd/src/test/java/org/azd/DistributedTaskApiTest.java new file mode 100644 index 00000000..6f56562a --- /dev/null +++ b/azd/src/test/java/org/azd/DistributedTaskApiTest.java @@ -0,0 +1,195 @@ +package org.azd; + +import org.azd.distributedtask.types.VariableGroupDefinition; +import org.azd.enums.VariableGroupType; +import org.azd.exceptions.AzDException; +import org.azd.exceptions.ConnectionException; +import org.azd.helpers.JsonMapper; +import org.azd.interfaces.AzDClient; +import org.azd.interfaces.CoreDetails; +import org.azd.interfaces.DistributedTaskDetails; +import org.azd.release.types.ProjectReference; +import org.azd.utils.AzDClientApi; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.util.HashMap; + +public class DistributedTaskApiTest { + private static final JsonMapper MAPPER = new JsonMapper(); + private static AzDClient webApi; + private static DistributedTaskDetails d; + private static CoreDetails c; + + + @Before + public void init() throws AzDException { + String dir = System.getProperty("user.dir"); + File file = new File(dir + "/src/test/java/org/azd/_unitTest.json"); + MockParameters m = MAPPER.mapJsonFromFile(file, MockParameters.class); + String organization = m.getO(); + String token = m.getT(); + String project = m.getP(); + webApi = new AzDClientApi(organization, project, token); + d = webApi.getDistributedTaskApi(); + c = webApi.getCoreApi(); + } + + @Test + public void shouldGetAnAgentInAPool() throws ConnectionException, AzDException { + d.getAgent(9, 8); + } + + @Test + public void shouldGetAllAgentsInAPool() throws ConnectionException, AzDException { + d.getAgents(9); + } + + @Test(expected = AzDException.class) + public void shouldAddADeploymentGroup() throws ConnectionException, AzDException { + d.addDeploymentGroup("myDeploymentGroup", "Deployments to test VMs"); + } + + @Test + public void shouldGetAllDeploymentGroups() throws ConnectionException, AzDException { + d.getDeploymentGroups(); + } + + @Test + public void shouldGetADeploymentGroup() throws ConnectionException, AzDException { + d.getDeploymentGroup(2944); + } + + @Test + public void shouldDeleteADeploymentGroup() throws ConnectionException, AzDException { + // create a new deployment group + var deploymentGroup = d.addDeploymentGroup("newDeploymentGroup", "New Deployment group"); + d.deleteDeploymentGroup(deploymentGroup.getId()); + } + + @Test + public void shouldUpdateADeploymentGroup() throws ConnectionException, AzDException { + // create a new deployment group, update it and delete it. + var deploymentGroup = d.getDeploymentGroup(2947); + d.updateDeploymentGroup(deploymentGroup.getId(), deploymentGroup.getName(), "Description for new deployment group"); + } + + @Test(expected = AzDException.class) + public void shouldAddANewEnvironment() throws ConnectionException, AzDException { + d.addEnvironment("newEnvironment", "New testing environment"); + } + + @Test + public void shouldGetAnEnvironment() throws ConnectionException, AzDException { + d.getEnvironment(1); + } + + @Test + public void shouldReturnListOfEnvironments() throws ConnectionException, AzDException { + d.getEnvironments(); + } + + @Test + public void shouldDeleteAnEnvironment() throws ConnectionException, AzDException { + var env = d.addEnvironment("EnvironmentToDelete", "Environment created for testing deletion functionality"); + d.deleteEnvironment(env.getId()); + } + + @Test + public void shouldUpdateAnEnvironment() throws ConnectionException, AzDException { + d.updateEnvironment(4, "EnvironmentToUpdate", "Environment created for testing update functionality"); + } + + @Test(expected = AzDException.class) + public void shouldAddANewVariableGroup() throws ConnectionException, AzDException { + var variableGroupDefinition = new VariableGroupDefinition(); + var projectReference = new ProjectReference(); + + var project = c.getProject("azure-devops-java-sdk"); + + projectReference.setName(project.getName()); + projectReference.setId(project.getId()); + + var variables = new HashMap(){{ + put("userName", new HashMap(){{ + put("value", "testUser"); + }}); + put("passCode", new HashMap(){{ + put("value", 2255); + }}); + put("details", new HashMap(){{ + put("value", "Test Value"); + put("isSecret", true); + }}); + }}; + + variableGroupDefinition.setName("testGroup"); + variableGroupDefinition.setDescription("This is a test variable group"); + variableGroupDefinition.setType(VariableGroupType.Vsts); + variableGroupDefinition.setVariables(variables); + variableGroupDefinition.setProjectReference(projectReference); + + d.addVariableGroup(variableGroupDefinition); + } + + @Test(expected = AzDException.class) + public void shouldAddANewVariableGroupToDefaultProject() throws ConnectionException, AzDException { + var variables = new HashMap(){{ + put("userName", new HashMap(){{ + put("value", "testUser"); + }}); + put("passCode", new HashMap(){{ + put("value", 2255); + }}); + put("details", new HashMap(){{ + put("value", "Test Value"); + put("isSecret", true); + }}); + }}; + + d.addVariableGroup("test", "test group", variables); + } + + @Test + public void shouldGetVariableGroups() throws ConnectionException, AzDException { + d.getVariableGroups(); + } + + @Test + public void shouldDeleteAVariableGroup() throws ConnectionException, AzDException { + var variables = new HashMap<>(){{ + put("userName", new HashMap<>(){{ + put("value", "testUser"); + }}); + }}; + + var projectId = c.getProject("azure-devops-java-sdk").getId(); + + var group = d.addVariableGroup("newVariableGroup", "Meant for testing deletion functionality", variables); + + d.deleteVariableGroup(group.getId(), new String[]{projectId}); + } + + @Test + public void shouldUpdateAVariableGroup() throws ConnectionException, AzDException { + var variablesToUpdate = new HashMap<>(){{ + put("userName", new HashMap<>(){{ + put("value", "testUser"); + }}); + + put("password", new HashMap<>(){{ + put("value", "testUser"); + put("isSecret", true); + }}); + }}; + + var group = d.getVariableGroups("newVariableGroupToUpdate") + .getVariableGroups() + .stream() + .findFirst() + .get(); + + d.updateVariableGroup(group.getId(), group.getName(), group.getDescription(), variablesToUpdate); + } +} diff --git a/azd/src/test/java/org/azd/PipelinesTest.java b/azd/src/test/java/org/azd/PipelinesTest.java index 33ee836b..c97d4284 100644 --- a/azd/src/test/java/org/azd/PipelinesTest.java +++ b/azd/src/test/java/org/azd/PipelinesTest.java @@ -35,15 +35,15 @@ public void init() throws AzDException { @Test public void shouldGetArtifacts() throws ConnectionException, AzDException, IOException { - p.getArtifacts(8, 515, "drop"); + p.getArtifacts(8, 531, "drop"); } @Test public void shouldGetArtifactsWithContentsExpanded() throws ConnectionException, AzDException, IOException { -// String url = p.getArtifacts(8, 515, "drop", PipelinesArtifactExpandOptions.SIGNEDCONTENT).getSignedContent().getUrl(); +// String url = p.getArtifacts(8, 531, "drop", PipelinesArtifactExpandOptions.SIGNEDCONTENT).getSignedContent().getUrl(); // new FileOutputStream("drop.zip").getChannel().transferFrom(Channels.newChannel( // new URL(url).openStream()), 0, Long.MAX_VALUE); - p.getArtifacts(8, 515, "drop", PipelinesExpandOptions.SIGNEDCONTENT); + p.getArtifacts(8, 531, "drop", PipelinesExpandOptions.SIGNEDCONTENT); } @Test @@ -53,17 +53,17 @@ public void shouldGetPipelines() throws ConnectionException, AzDException, IOExc @Test public void shouldGetPipelineLog() throws ConnectionException, AzDException, IOException { - p.getPipelineLog(8, 515, 1); + p.getPipelineLog(8, 531, 1); } @Test public void shouldGetPipelineLogWithOptions() throws ConnectionException, AzDException, IOException { - p.getPipelineLog(8, 515, 1, PipelinesExpandOptions.SIGNEDCONTENT); + p.getPipelineLog(8, 531, 1, PipelinesExpandOptions.SIGNEDCONTENT); } @Test public void shouldGetPipelineLogs() throws ConnectionException, AzDException, IOException { - p.getPipelineLogs(8, 515); + p.getPipelineLogs(8, 531); } // Should throw PipelineExistsException;