use of com.vmware.xenon.common.ServiceStateMapUpdateRequest in project photon-model by vmware.
the class ResourceGroomerTaskService method createResourceGroupEndpointLinkPatchOp.
/**
* Creates an operation with ServiceStateMapUpdateRequest for updating customProperties.__endpointLink
* in ResourceGroupStates and AuthCredentialsServiceState
*/
private Operation createResourceGroupEndpointLinkPatchOp(String documentLink, String endpointLink) {
Map<Object, Object> customProperty = new HashMap<>();
customProperty.put(CUSTOM_PROP_ENDPOINT_LINK, endpointLink);
Map<String, Map<Object, Object>> entriesToAdd = new HashMap<>();
entriesToAdd.put(ResourceGroupState.FIELD_NAME_CUSTOM_PROPERTIES, customProperty);
ServiceStateMapUpdateRequest request = ServiceStateMapUpdateRequest.create(entriesToAdd, null);
return Operation.createPatch(this.getHost(), documentLink).setReferer(this.getUri()).setBody(request);
}
use of com.vmware.xenon.common.ServiceStateMapUpdateRequest in project photon-model by vmware.
the class ResourceEnumerationTaskService method updateEndpointState.
private DeferredResult<Operation> updateEndpointState(ResourceEnumerationTaskState currentState) {
TaskStage taskStage = currentState.taskInfo.stage;
String stageName = taskStage.name();
String message = null;
String messageId = null;
if (currentState.taskInfo.failure != null) {
message = currentState.taskInfo.failure.message;
messageId = currentState.taskInfo.failure.messageId;
}
Map<Object, Object> cpToAdd = new HashMap<>();
cpToAdd.put(EP_CP_ENUMERATION_TASK_STATE, stageName);
Collection<String> cpToRemove = new LinkedList<>();
if (message != null && message.length() > 0) {
cpToAdd.put(EP_CP_ENUMERATION_TASK_MESSAGE, message);
} else {
cpToRemove.add(EP_CP_ENUMERATION_TASK_MESSAGE);
}
if (messageId != null && messageId.length() > 0) {
cpToAdd.put(EP_CP_ENUMERATION_TASK_MESSAGE_ID, messageId);
} else {
cpToRemove.add(EP_CP_ENUMERATION_TASK_MESSAGE_ID);
}
Map<String, Map<Object, Object>> entriesToAdd = Collections.singletonMap(ResourceState.FIELD_NAME_CUSTOM_PROPERTIES, cpToAdd);
Map<String, Collection<Object>> keysToRemove = Collections.singletonMap(EndpointState.FIELD_NAME_CUSTOM_PROPERTIES, new HashSet<>(cpToRemove));
ServiceStateMapUpdateRequest mapUpdateRequest = ServiceStateMapUpdateRequest.create(entriesToAdd, keysToRemove);
return sendWithDeferredResult(Operation.createPatch(this, currentState.endpointLink).setBody(mapUpdateRequest)).exceptionally(err -> {
logWarning("Cannot patch custom properties of" + " endpoint '%s' to stageName '%s'. Cause: %s", currentState.endpointLink, stageName, Utils.toString(err));
return null;
});
}
Aggregations