Search in sources :

Example 1 with ServiceStateMapUpdateRequest

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);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ServiceStateMapUpdateRequest(com.vmware.xenon.common.ServiceStateMapUpdateRequest)

Example 2 with ServiceStateMapUpdateRequest

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;
    });
}
Also used : HashMap(java.util.HashMap) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) LinkedList(java.util.LinkedList) ServiceStateMapUpdateRequest(com.vmware.xenon.common.ServiceStateMapUpdateRequest) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ServiceStateMapUpdateRequest (com.vmware.xenon.common.ServiceStateMapUpdateRequest)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TaskStage (com.vmware.xenon.common.TaskState.TaskStage)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1