Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.vmware.pscoe.iac.artifact.aria.operations.models.AlertDefinitionDTO;
import com.vmware.pscoe.iac.artifact.aria.operations.models.AlertDefinitionDTO.AlertDefinition.State;
import com.vmware.pscoe.iac.artifact.aria.operations.models.AlertDefinitionDTO.AlertDefinition.SymptomSet;
import com.vmware.pscoe.iac.artifact.aria.operations.models.SupermetricDTO.SuperMetric;
import com.vmware.pscoe.iac.artifact.aria.operations.models.AuthGroupDTO;
import com.vmware.pscoe.iac.artifact.aria.operations.models.AuthGroupsDTO;
import com.vmware.pscoe.iac.artifact.aria.operations.models.AuthUserDTO;
Expand Down Expand Up @@ -99,10 +100,18 @@ public class RestClientVrops extends RestClient {
* ALERT_DEFS_API.
*/
private static final String ALERT_DEFS_API = PUBLIC_API_PREFIX + "alertdefinitions/";
/**
* GET_ALL_ALERT_DEFS_API.
*/
private static final String GET_ALL_ALERTS_DEFS_API = PUBLIC_API_PREFIX + "alertdefinitions";
/**
* SYMPTOM_DEFS_API.
*/
private static final String SYMPTOM_DEFS_API = PUBLIC_API_PREFIX + "symptomdefinitions/";
/**
* GET_ALL_SYMPTOM_DEFS_API.
*/
private static final String GET_ALL_SYMPTOM_DEFS_API = PUBLIC_API_PREFIX + "symptomdefinitions";
/**
* POLICIES_API.
*/
Expand Down Expand Up @@ -151,6 +160,10 @@ public class RestClientVrops extends RestClient {
* RECOMMENDATIONS_API.
*/
private static final String RECOMMENDATIONS_API = PUBLIC_API_PREFIX + "recommendations/";
/**
* GET_ALL_RECOMMENDATIONS_API.
*/
private static final String GET_ALL_RECOMMENDATIONS_API = PUBLIC_API_PREFIX + "recommendations";
/**
* RESOURCES_API.
*/
Expand Down Expand Up @@ -406,7 +419,8 @@ public void importPolicyFromZip(String policyName, File file, Boolean force) thr

HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
try {
restTemplate.postForEntity(uri, requestEntity, String.class);
ResponseEntity<String> response = restTemplate.postForEntity(uri, requestEntity, String.class);
logger.info("Import policy from zip response:\n" + response);
} catch (RestClientException e) {
throw new RuntimeException(
String.format("The policy '%s' could not be imported : %s.", policyName, e.getMessage()), e);
Expand Down Expand Up @@ -726,6 +740,78 @@ public void applyPolicyToCustomGroups(PolicyDTO.Policy policy, List<CustomGroupD
}
}

/**
* Reads all definition entities entities of sepcified type
* @param definitionType the type of definition about to be read from vROps
* @return list of the definitions
*/
public List<?> getAlltDefinitionsOfType(VropsPackageMemberType definitionType) {

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);

// older vROPs versions use internal API for policies, thus internal header
// needs to be set.
if (!this.isVersionAbove812()) {
headers.set(INTERNAL_API_HEADER_NAME, Boolean.TRUE.toString());
}
HttpEntity<String> entity = new HttpEntity<>(headers);
ResponseEntity<String> response = new ResponseEntity<String>(HttpStatus.OK);

String url = "";
switch (definitionType) {
case ALERT_DEFINITION:
url = GET_ALL_ALERTS_DEFS_API;
break;
case SYMPTOM_DEFINITION:
url = GET_ALL_SYMPTOM_DEFS_API;
break;
case RECOMMENDATION:
url = GET_ALL_RECOMMENDATIONS_API;
break;
default:
throw new RuntimeException("Unknown definition type used");
}

try {
UriComponentsBuilder uriBuilder;
// for newer vROPs versions the policies API is no longer internal.
if (this.isVersionAbove812()) {
uriBuilder = UriComponentsBuilder.fromUri(getURI(getURIBuilder().setPath(url)));
} else {
uriBuilder = UriComponentsBuilder.fromUri(getURI(getURIBuilder().setPath(url)));
}
uriBuilder.queryParam("pageSize", DEFAULT_PAGE_SIZE);
URI restUri = uriBuilder.build().toUri();
response = restTemplate.exchange(restUri, HttpMethod.GET, entity, String.class);
} catch (HttpClientErrorException e) {
if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
return new ArrayList<>();
}
throw new RuntimeException(
String.format("HTTP error ocurred trying to fetching definitions of type %s. Message: %s, Server error: %s",
definitionType.toString(), e.getMessage(), e.getStatusText()));
} catch (Exception e) {
throw new RuntimeException(
String.format("General error while fetching definitions of type %s. Message: %s, Server error: %s",
definitionType.toString(), e.getMessage(), response.getBody()));
}

switch (definitionType) {
case ALERT_DEFINITION:
AlertDefinitionDTO alarmDefinitionDTO = (AlertDefinitionDTO) deserializeDefinitions(definitionType, response.getBody());
return alarmDefinitionDTO.getAlertDefinitions();
case SYMPTOM_DEFINITION:
SymptomDefinitionDTO symptomDefinitionDTO = (SymptomDefinitionDTO) deserializeDefinitions(definitionType, response.getBody());
return symptomDefinitionDTO.getSymptomDefinitions();
case RECOMMENDATION:
RecommendationDTO recommendationDTO = (RecommendationDTO) deserializeDefinitions(definitionType, response.getBody());
return recommendationDTO.getRecommendations();
default:
return new ArrayList<>();
}
}

/**
* Export custom groups filtered by list of custom group names.
*
Expand Down Expand Up @@ -1175,6 +1261,14 @@ public SupermetricDTO getAllSupermetrics() {
return retVal;
}

/**
* Imports all Supermetrics specified in the content.yaml
*/
public void importSupermetrics() {

List<SuperMetric> existingSupermetrics = getAllSupermetrics().getSuperMetrics();
}

/**
* Get all vROPs view definitions.
*
Expand Down
Loading
Loading