Skip to content

Commit

Permalink
refactor(vro): Restructure
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Genov <[email protected]>
  • Loading branch information
Michaelpalacce committed Jan 20, 2025
1 parent fa06470 commit cdf3464
Show file tree
Hide file tree
Showing 23 changed files with 139 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The structure of this folder is being reworked. Classes are being moved based on
## Progress

- [x] Aria Automation
- [ ] Aria Orchestrator
- [x] Aria Orchestrator
- [x] Aria Logs
- [x] Aria Operations
- [ ] SSH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
import com.vmware.pscoe.iac.artifact.aria.operations.configuration.ConfigurationVrops;
import com.vmware.pscoe.iac.artifact.aria.operations.rest.RestClientVrops;
import com.vmware.pscoe.iac.artifact.aria.operations.store.VropsPackageStore;
import com.vmware.pscoe.iac.artifact.aria.orchestrator.configuration.ConfigurationVro;
import com.vmware.pscoe.iac.artifact.aria.orchestrator.configuration.ConfigurationVroNg;
import com.vmware.pscoe.iac.artifact.aria.orchestrator.rest.RestClientVro;
import com.vmware.pscoe.iac.artifact.aria.orchestrator.store.VroPackageStore;
import com.vmware.pscoe.iac.artifact.aria.automation.configuration.ConfigurationVraNg;
import com.vmware.pscoe.iac.artifact.aria.automation.pack.VraNgPackageStore;
import com.vmware.pscoe.iac.artifact.cli.CliManagerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,25 @@
import java.time.Instant;
import java.util.*;

import com.vmware.pscoe.iac.artifact.model.vro.WorkflowExecution;
import com.vmware.pscoe.iac.artifact.rest.RestClientVro;
import com.vmware.pscoe.iac.artifact.aria.orchestrator.model.WorkflowExecution;
import com.vmware.pscoe.iac.artifact.aria.orchestrator.rest.RestClientVro;

public class VroWorkflowExecutor {

// ANSI Console Color Text Escape Sequences.
private static final String BRIGHT_FOREGROUND = "\u001B[90m";
private static final String NORMAL_FOREGROUND = "\u001B[39m";
private static final String NORMAL = "\u001B[0m";
private static final String BRIGHT_RED = "\u001B[1;31m";
private static final String RED = "\u001B[0;31m";
private static final String BRIGHT_YELLOW = "\u001B[1;33m";
private static final String YELLOW = "\u001B[0;33m";
private static final String GREEN = "\u001B[0;32m";
private static final String NORMAL = "\u001B[0m";
private static final String BRIGHT_RED = "\u001B[1;31m";
private static final String RED = "\u001B[0;31m";
private static final String BRIGHT_YELLOW = "\u001B[1;33m";
private static final String YELLOW = "\u001B[0;33m";
private static final String GREEN = "\u001B[0;32m";
private static final Integer WORKFLOW_FINISH_POLL_INTERVAL = 250;
private static final Integer WORKFLOW_EXEC_POLL_INTERVAL = 1000;

private static final long SERVICE_UNAVAILABLE_SLEEP_MILLIS = 60000; // How long to sleep before retrying in case the service is not available.
private static final long SERVICE_UNAVAILABLE_SLEEP_MILLIS = 60000; // How long to sleep before retrying in case the
// service is not available.

private RestClientVro restClient;

Expand All @@ -49,15 +50,18 @@ public VroWorkflowExecutor(RestClientVro restClient) {
* Executes a workflow synchronously and waits for it to finish/fail
*
* @param workflowId - The ID of the workflow
* @param params - Properties containing the input parameters of the workflow
* @param params - Properties containing the input parameters of the
* workflow
* @param timeout - Timeout (in seconds) to wait for the workflow to finish
* @return Properties containing all string output parameters of the workflow
* @throws WorkflowExecutionException exception
*/
public WorkflowExecution executeWorkflow(String workflowId, Properties params, int timeout) throws WorkflowExecutionException {
public WorkflowExecution executeWorkflow(String workflowId, Properties params, int timeout)
throws WorkflowExecutionException {
// check whether workflow exists prior execution
if (!restClient.isWorkflowExisting(workflowId)) {
throw new WorkflowExecutionException(String.format("The workflow '%s' cannot be found on the target VRO '%s'", workflowId, restClient.getHost()));
throw new WorkflowExecutionException(String.format(
"The workflow '%s' cannot be found on the target VRO '%s'", workflowId, restClient.getHost()));
}
Properties inputParametersTypes = restClient.getInputParametersTypes(workflowId);

Expand Down Expand Up @@ -103,7 +107,8 @@ private boolean workflowFinished(RestClientVro restClient, String workflowId, St
}
}

private long printLogMessages(String workflowId, String executionId, long lastLogTimestamp, Set<String> printedMessages) {
private long printLogMessages(String workflowId, String executionId, long lastLogTimestamp,
Set<String> printedMessages) {
try {
final long timestamp = Instant.now().minus(Duration.ofSeconds(30)).toEpochMilli();
final List<String> logs = restClient.getWorkflowLogs(workflowId, executionId, "debug", lastLogTimestamp);
Expand All @@ -112,7 +117,7 @@ private long printLogMessages(String workflowId, String executionId, long lastLo
final String colorMsg = (msg)
.replaceFirst("\\[(.+?)]", "[" + BRIGHT_FOREGROUND + "$1" + NORMAL_FOREGROUND + "]")
.replaceFirst("(?s)\\[warning](.+)", BRIGHT_YELLOW + "[warning]" + YELLOW + "$1" + NORMAL)
.replaceFirst("(?s)\\[error](.+)" , BRIGHT_RED + "[error]" + RED + "$1" + NORMAL);
.replaceFirst("(?s)\\[error](.+)", BRIGHT_RED + "[error]" + RED + "$1" + NORMAL);
System.out.println(colorMsg);
printedMessages.add(msg);
}
Expand All @@ -129,7 +134,8 @@ private void handleServiceUnavailableException(String failedOperation, String wo
+ NORMAL + rte.getClass().getName() + " : " + rte.getLocalizedMessage() + ". "
+ GREEN + "Sleeping for " + SERVICE_UNAVAILABLE_SLEEP_MILLIS + " milliseconds." + NORMAL);
printStackTrace(rte);
sleepSilently(SERVICE_UNAVAILABLE_SLEEP_MILLIS); // Give it some more time to recover (1 minute more) and do not fill up the logs so quickly
sleepSilently(SERVICE_UNAVAILABLE_SLEEP_MILLIS); // Give it some more time to recover (1 minute more) and do not
// fill up the logs so quickly
}

private void sleepSilently(long millis) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
* #L%
*/
package com.vmware.pscoe.iac.artifact.configuration;
package com.vmware.pscoe.iac.artifact.aria.orchestrator.configuration;

import java.net.URISyntaxException;
import java.util.Properties;
Expand All @@ -21,6 +21,9 @@
import org.apache.hc.core5.http.HttpHost;
import org.springframework.util.StringUtils;

import com.vmware.pscoe.iac.artifact.configuration.ConfigurationException;
import com.vmware.pscoe.iac.artifact.configuration.ConfigurationNg;
import com.vmware.pscoe.iac.artifact.configuration.ConfigurationWithRefreshToken;
import com.vmware.pscoe.iac.artifact.model.PackageType;

public class ConfigurationVro extends ConfigurationWithRefreshToken implements ConfigurationNg {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
* This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
* #L%
*/
package com.vmware.pscoe.iac.artifact.configuration;
package com.vmware.pscoe.iac.artifact.aria.orchestrator.configuration;

import org.springframework.util.StringUtils;

import com.vmware.pscoe.iac.artifact.aria.automation.configuration.ConfigurationVraNg;
import com.vmware.pscoe.iac.artifact.configuration.ConfigurationException;
import com.vmware.pscoe.iac.artifact.configuration.ConfigurationNg;

import java.util.Properties;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
* This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
* #L%
*/
package com.vmware.pscoe.iac.artifact.model.vro;
package com.vmware.pscoe.iac.artifact.aria.orchestrator.model;

import java.util.List;

import com.vmware.pscoe.iac.artifact.model.PackageContent;

public class VroPackageContent extends PackageContent<VroPackageContent.ContentType> {
public enum ContentType implements PackageContent.ContentType {

public enum ContentType implements PackageContent.ContentType {
WORKFLOW, ACTION, CONFIGURATION, RESOURCE
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
* #L%
*/
package com.vmware.pscoe.iac.artifact.model.vro;
package com.vmware.pscoe.iac.artifact.aria.orchestrator.model;

import java.io.File;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
* #L%
*/
package com.vmware.pscoe.iac.artifact.model.vro;
package com.vmware.pscoe.iac.artifact.aria.orchestrator.model;

import java.util.Properties;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
* This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
* #L%
*/
package com.vmware.pscoe.iac.artifact.model.vro;
package com.vmware.pscoe.iac.artifact.aria.orchestrator.model;

import java.io.Serializable;

public interface WorkflowParameterValue extends Serializable {}
public interface WorkflowParameterValue extends Serializable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
* #L%
*/
package com.vmware.pscoe.iac.artifact.model.vro;
package com.vmware.pscoe.iac.artifact.aria.orchestrator.model;

import java.io.Serializable;
import java.util.ArrayList;
Expand All @@ -30,7 +30,6 @@
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.google.gson.annotations.SerializedName;


@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "parameters" })
public class WorkflowParameters implements Serializable {
Expand Down Expand Up @@ -236,18 +235,18 @@ public static class BooleanValue implements WorkflowParameterValue {

@JsonProperty("boolean")
@SerializedName(value = "boolean")
private com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.Bool bool;
private WorkflowParameters.Bool bool;

@JsonIgnore
private transient Map<java.lang.String, Object> additionalProperties = new HashMap<>();

@JsonProperty("boolean")
public com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.Bool getBoolean() {
public WorkflowParameters.Bool getBoolean() {
return bool;
}

@JsonProperty("boolean")
public void setBoolean(com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.Bool bool) {
public void setBoolean(WorkflowParameters.Bool bool) {
this.bool = bool;
}

Expand All @@ -268,18 +267,18 @@ public static class NumberValue implements WorkflowParameterValue {
private static final long serialVersionUID = 3534736269209803202L;

@JsonProperty("number")
private com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.Number number;
private WorkflowParameters.Number number;

@JsonIgnore
private transient Map<java.lang.String, Object> additionalProperties = new HashMap<>();

@JsonProperty("number")
public com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.Number getNumber() {
public WorkflowParameters.Number getNumber() {
return number;
}

@JsonProperty("number")
public void setNumber(com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.Number number) {
public void setNumber(WorkflowParameters.Number number) {
this.number = number;
}

Expand All @@ -300,18 +299,18 @@ public static class StringValue implements WorkflowParameterValue {
private static final long serialVersionUID = 8624736269209802096L;

@JsonProperty("string")
private com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.String string;
private WorkflowParameters.String string;

@JsonIgnore
private transient Map<java.lang.String, Object> additionalProperties = new HashMap<>();

@JsonProperty("string")
public com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.String getString() {
public WorkflowParameters.String getString() {
return string;
}

@JsonProperty("string")
public void setString(com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.String string) {
public void setString(WorkflowParameters.String string) {
this.string = string;
}

Expand All @@ -332,18 +331,18 @@ public static class ArrayStringValue implements WorkflowParameterValue {
private static final long serialVersionUID = 8945736269209803399L;

@JsonProperty("array")
private com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.ArrayElements array;
private WorkflowParameters.ArrayElements array;

@JsonIgnore
private transient Map<java.lang.String, Object> additionalProperties = new HashMap<>();

@JsonProperty("array")
public com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.ArrayElements getArray() {
public WorkflowParameters.ArrayElements getArray() {
return array;
}

@JsonProperty("array")
public void setArray(com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.ArrayElements array) {
public void setArray(WorkflowParameters.ArrayElements array) {
this.array = array;
}

Expand All @@ -364,26 +363,26 @@ public static class ArrayElements implements Serializable {
private static final long serialVersionUID = 8934736269209802297L;

@JsonProperty("elements")
private List<com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.StringValue> elements = new ArrayList<>();
private List<WorkflowParameters.StringValue> elements = new ArrayList<>();

@JsonIgnore
private transient Map<java.lang.String, Object> additionalProperties = new HashMap<>();

@JsonProperty("elements")
public List<com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.StringValue> getElements() {
public List<WorkflowParameters.StringValue> getElements() {
return elements;
}

@JsonProperty("elements")
public void setElements(List<com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.StringValue> elements) {
public void setElements(List<WorkflowParameters.StringValue> elements) {
this.elements = elements;
}

@JsonAnyGetter
public Map<java.lang.String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(java.lang.String name, Object value) {
this.additionalProperties.put(name, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
* #L%
*/
package com.vmware.pscoe.iac.artifact.rest;
package com.vmware.pscoe.iac.artifact.aria.orchestrator.rest;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -60,22 +60,23 @@
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;
import com.vmware.pscoe.iac.artifact.aria.orchestrator.model.VroPackageContent;
import com.vmware.pscoe.iac.artifact.aria.orchestrator.model.VroPackageContent.ContentType;
import com.vmware.pscoe.iac.artifact.aria.orchestrator.model.WorkflowExecution;
import com.vmware.pscoe.iac.artifact.aria.orchestrator.model.WorkflowParameters;
import com.vmware.pscoe.iac.artifact.aria.orchestrator.model.WorkflowParameters.ArrayElements;
import com.vmware.pscoe.iac.artifact.aria.orchestrator.model.WorkflowParameters.ArrayStringValue;
import com.vmware.pscoe.iac.artifact.aria.orchestrator.model.WorkflowParameters.BooleanValue;
import com.vmware.pscoe.iac.artifact.aria.orchestrator.model.WorkflowParameters.NumberValue;
import com.vmware.pscoe.iac.artifact.aria.orchestrator.model.WorkflowParameters.Parameter;
import com.vmware.pscoe.iac.artifact.aria.orchestrator.model.WorkflowParameters.StringValue;
import com.vmware.pscoe.iac.artifact.configuration.Configuration;
import com.vmware.pscoe.iac.artifact.configuration.ConfigurationNg;
import com.vmware.pscoe.iac.artifact.model.Package;
import com.vmware.pscoe.iac.artifact.model.PackageContent.Content;
import com.vmware.pscoe.iac.artifact.model.PackageFactory;
import com.vmware.pscoe.iac.artifact.model.PackageType;
import com.vmware.pscoe.iac.artifact.model.vro.VroPackageContent;
import com.vmware.pscoe.iac.artifact.model.vro.VroPackageContent.ContentType;
import com.vmware.pscoe.iac.artifact.model.vro.WorkflowExecution;
import com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters;
import com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.Parameter;
import com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.StringValue;
import com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.ArrayElements;
import com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.ArrayStringValue;
import com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.BooleanValue;
import com.vmware.pscoe.iac.artifact.model.vro.WorkflowParameters.NumberValue;
import com.vmware.pscoe.iac.artifact.rest.RestClient;

public class RestClientVro extends RestClient {

Expand Down Expand Up @@ -132,7 +133,7 @@ protected Configuration getConfiguration() {
* Automation Orchestrator)
* @param restTemplate REST Template.
*/
protected RestClientVro(ConfigurationNg configuration, RestTemplate restTemplate) {
public RestClientVro(ConfigurationNg configuration, RestTemplate restTemplate) {
this.configuration = configuration;
this.restTemplate = restTemplate;
}
Expand Down
Loading

0 comments on commit cdf3464

Please sign in to comment.