Example usage for org.apache.commons.lang3.tuple ImmutablePair getLeft

List of usage examples for org.apache.commons.lang3.tuple ImmutablePair getLeft

Introduction

In this page you can find the example usage for org.apache.commons.lang3.tuple ImmutablePair getLeft.

Prototype

@Override
public L getLeft() 

Source Link

Usage

From source file:org.opendaylight.vpnservice.dhcpservice.DhcpPktHandler.java

private ImmutablePair<BigInteger, String> getDpnIdPhysicalAddressFromInterfaceName(String interfaceName) {
    ImmutablePair<BigInteger, String> pair = dhcpMgr.getInterfaceCache(interfaceName);
    if (pair != null && pair.getLeft() != null && pair.getRight() != null) {
        return pair;
    }//from w  w w.j  av a  2  s  .c o  m
    NodeConnectorId nodeConnectorId = null;
    org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState = getInterfaceStateFromOperDS(
            interfaceName);
    if (interfaceState != null) {
        List<String> ofportIds = interfaceState.getLowerLayerIf();
        nodeConnectorId = new NodeConnectorId(ofportIds.get(0));
    }
    BigInteger dpId = BigInteger.valueOf(MDSALUtil.getDpnIdFromPortName(nodeConnectorId));
    String phyAddress = interfaceState == null ? "" : interfaceState.getPhysAddress().getValue();
    pair = new ImmutablePair<BigInteger, String>(dpId, phyAddress);
    dhcpMgr.updateInterfaceCache(interfaceName, pair);
    return pair;
}

From source file:org.openecomp.sdc.asdctool.impl.migration.v1604.ServiceMigration.java

private boolean fillEdgeProperties(ComponentInstanceData instance, Map<String, Object> props) {
    if (instance.getComponentInstDataDefinition().getOriginType().equals(OriginTypeEnum.VF)) {
        Either<List<ImmutablePair<ComponentInstanceData, GraphEdge>>, TitanOperationStatus> vfci = titanGenericDao
                .getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Resource),
                        instance.getComponentInstDataDefinition().getComponentUid(),
                        GraphEdgeLabels.RESOURCE_INST, NodeTypeEnum.ResourceInstance,
                        ComponentInstanceData.class);
        if (vfci.isRight()) {
            log.debug(/*w  w w.j  av a2s .  c  o  m*/
                    "createCalculatedCapabilitiesForInstance failed to fetch instance for resource {} error: {}",
                    instance.getComponentInstDataDefinition().getComponentUid(), vfci.right().value());
            return false;
        }
        ImmutablePair<ComponentInstanceData, GraphEdge> immutablePair = vfci.left().value().get(0);
        String vfciId = immutablePair.getLeft().getUniqueId();
        props.put(GraphEdgePropertiesDictionary.OWNER_ID.getProperty(), vfciId);
        props.put(GraphEdgePropertiesDictionary.SOURCE.getProperty(),
                immutablePair.getLeft().getComponentInstDataDefinition().getComponentUid());

    } else {
        props.put(GraphEdgePropertiesDictionary.OWNER_ID.getProperty(), instance.getUniqueId());
        props.put(GraphEdgePropertiesDictionary.SOURCE.getProperty(),
                instance.getComponentInstDataDefinition().getComponentUid());
    }
    return true;
}

From source file:org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.java

/**
 * upload an artifact to a resource instance by UUID
 * //  w  w  w . ja v  a  2 s  .  c  om
 * @param data
 * @param request
 * @param componentType
 * @param componentUuid
 * @param resourceInstanceName
 * @param additionalParams
 * @return
 */
public Either<ArtifactDefinition, ResponseFormat> uploadArtifactToRiByUUID(String data,
        HttpServletRequest request, ComponentTypeEnum componentType, String componentUuid,
        String resourceInstanceName, Map<AuditingFieldsKeysEnum, Object> additionalParams) {
    Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
    Either<ArtifactDefinition, ResponseFormat> uploadArtifactResult;
    Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = null;
    ArtifactDefinition uploadArtifact;
    Component component = null;
    String componentInstanceId;
    String componentId;
    String origMd5 = request.getHeader(Constants.MD5_HEADER);
    String userId = request.getHeader(Constants.USER_ID_HEADER);

    ImmutablePair<Component, ComponentInstance> componentRiPair = null;
    Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = getComponentOperation(componentType)
            .getLatestComponentMetadataByUuid(componentType.getNodeType(), componentUuid);
    if (getComponentRes.isRight()) {
        StorageOperationStatus status = getComponentRes.right().value();
        log.debug("Could not fetch component with type {} and uuid {}. Status is {}. ", componentType,
                componentUuid, status);
        errorWrapper.setInnerElement(
                componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
    }
    if (errorWrapper.isEmpty() && !getComponentRes.left().value().getMetadataDataDefinition().getState()
            .equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
        component = checkoutParentComponent(componentType,
                getComponentRes.left().value().getMetadataDataDefinition().getUniqueId(), userId, errorWrapper);
    }
    if (errorWrapper.isEmpty()) {
        if (component == null) {
            componentRiPair = getRelatedComponentComponentInstance(componentType, componentUuid,
                    resourceInstanceName, errorWrapper);
        } else {
            componentRiPair = getRelatedComponentComponentInstance(component, resourceInstanceName,
                    errorWrapper);
        }
    }
    if (errorWrapper.isEmpty()) {
        componentInstanceId = componentRiPair.getRight().getUniqueId();
        componentId = componentRiPair.getLeft().getUniqueId();
        additionalParams.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceInstanceName);
        ArtifactOperation operation = ArtifactOperation.Create;
        operation.setExternalApi(true);
        ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data,
                ArtifactDefinition.class);

        actionResult = handleArtifactRequest(componentInstanceId, userId, ComponentTypeEnum.RESOURCE_INSTANCE,
                operation, null, artifactInfo, origMd5, data, null, null, componentId,
                ComponentTypeEnum.findParamByType(componentType));
        if (actionResult.isRight()) {
            log.debug(
                    "Failed to upload artifact to component instance {} of component with type {} and uuid {}. Status is {}. ",
                    resourceInstanceName, componentType, componentUuid, actionResult.right().value());
            errorWrapper.setInnerElement(actionResult.right().value());
        }
    }
    if (errorWrapper.isEmpty()) {
        uploadArtifact = actionResult.left().value().left().value();
        updateAuditParametersWithArtifactDefinition(additionalParams, uploadArtifact);
        uploadArtifactResult = Either.left(uploadArtifact);
    } else {
        uploadArtifactResult = Either.right(errorWrapper.getInnerElement());
    }
    return uploadArtifactResult;
}

From source file:org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.java

/**
 * updates an artifact on a resource instance by UUID
 * //from  w w  w .  j  a v a  2s  .  c  o  m
 * @param data
 * @param request
 * @param componentType
 * @param componentUuid
 * @param resourceInstanceName
 * @param artifactUUID
 * @param additionalParams
 * @return
 */
public Either<ArtifactDefinition, ResponseFormat> updateArtifactOnRiByUUID(String data,
        HttpServletRequest request, ComponentTypeEnum componentType, String componentUuid,
        String resourceInstanceName, String artifactUUID,
        Map<AuditingFieldsKeysEnum, Object> additionalParams) {

    Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
    Either<ArtifactDefinition, ResponseFormat> updateArtifactResult;
    Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = null;
    ArtifactDefinition updateArtifact;
    Component component = null;
    String componentInstanceId = null;
    String componentId = null;
    String artifactId = null;
    String origMd5 = request.getHeader(Constants.MD5_HEADER);
    String userId = request.getHeader(Constants.USER_ID_HEADER);

    ImmutablePair<Component, ComponentInstance> componentRiPair = null;
    Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = getComponentOperation(componentType)
            .getLatestComponentMetadataByUuid(componentType.getNodeType(), componentUuid);
    if (getComponentRes.isRight()) {
        StorageOperationStatus status = getComponentRes.right().value();
        log.debug("Could not fetch component with type {} and uuid {}. Status is {}. ", componentType,
                componentUuid, status);
        errorWrapper.setInnerElement(
                componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
    }
    if (errorWrapper.isEmpty() && !getComponentRes.left().value().getMetadataDataDefinition().getState()
            .equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
        component = checkoutParentComponent(componentType,
                getComponentRes.left().value().getMetadataDataDefinition().getUniqueId(), userId, errorWrapper);
    }
    if (errorWrapper.isEmpty()) {
        if (component == null) {
            componentRiPair = getRelatedComponentComponentInstance(componentType, componentUuid,
                    resourceInstanceName, errorWrapper);
        } else {
            componentRiPair = getRelatedComponentComponentInstance(component, resourceInstanceName,
                    errorWrapper);
        }
    }
    if (errorWrapper.isEmpty()) {
        componentInstanceId = componentRiPair.getRight().getUniqueId();
        componentId = componentRiPair.getLeft().getUniqueId();
        artifactId = getLatestParentArtifactDataIdByArtifactUUID(artifactUUID, errorWrapper,
                componentInstanceId, ComponentTypeEnum.RESOURCE_INSTANCE);
    }
    if (errorWrapper.isEmpty()) {
        additionalParams.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceInstanceName);
        ArtifactOperation operation = ArtifactOperation.Update;
        operation.setExternalApi(true);
        ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data,
                ArtifactDefinition.class);

        actionResult = handleArtifactRequest(componentInstanceId, userId, ComponentTypeEnum.RESOURCE_INSTANCE,
                operation, artifactId, artifactInfo, origMd5, data, null, null, componentId,
                ComponentTypeEnum.findParamByType(componentType));
        if (actionResult.isRight()) {
            log.debug(
                    "Failed to upload artifact to component instance {} of component with type {} and uuid {}. Status is {}. ",
                    resourceInstanceName, componentType, componentUuid, actionResult.right().value());
            errorWrapper.setInnerElement(actionResult.right().value());
        }
    }
    if (errorWrapper.isEmpty()) {
        updateArtifact = actionResult.left().value().left().value();
        updateAuditParametersWithArtifactDefinition(additionalParams, updateArtifact);
        updateArtifactResult = Either.left(updateArtifact);
    } else {
        updateArtifactResult = Either.right(errorWrapper.getInnerElement());
    }
    return updateArtifactResult;

}

From source file:org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.java

/**
 * deletes an artifact an a resource instance by UUID
 * /* w  w w  . jav  a  2  s. c  o m*/
 * @param request
 * @param componentType
 * @param componentUuid
 * @param resourceInstanceName
 * @param artifactUUID
 * @param additionalParams
 * @return
 */
public Either<ArtifactDefinition, ResponseFormat> deleteArtifactOnRiByUUID(HttpServletRequest request,
        ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName, String artifactUUID,
        Map<AuditingFieldsKeysEnum, Object> additionalParams) {

    Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
    Either<ArtifactDefinition, ResponseFormat> deleteArtifactResult;
    Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = null;
    ArtifactDefinition deleteArtifact;
    Component component = null;
    String componentInstanceId = null;
    String componentId = null;
    String artifactId = null;
    String origMd5 = request.getHeader(Constants.MD5_HEADER);
    String userId = request.getHeader(Constants.USER_ID_HEADER);
    ImmutablePair<Component, ComponentInstance> componentRiPair = null;
    Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = getComponentOperation(componentType)
            .getLatestComponentMetadataByUuid(componentType.getNodeType(), componentUuid);
    if (getComponentRes.isRight()) {
        StorageOperationStatus status = getComponentRes.right().value();
        log.debug("Could not fetch component with type {} and uuid {}. Status is {}. ", componentType,
                componentUuid, status);
        errorWrapper.setInnerElement(
                componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
    }
    if (errorWrapper.isEmpty() && !getComponentRes.left().value().getMetadataDataDefinition().getState()
            .equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
        component = checkoutParentComponent(componentType,
                getComponentRes.left().value().getMetadataDataDefinition().getUniqueId(), userId, errorWrapper);
    }
    if (errorWrapper.isEmpty()) {
        if (component == null) {
            componentRiPair = getRelatedComponentComponentInstance(componentType, componentUuid,
                    resourceInstanceName, errorWrapper);
        } else {
            componentRiPair = getRelatedComponentComponentInstance(component, resourceInstanceName,
                    errorWrapper);
        }
    }
    if (errorWrapper.isEmpty()) {
        componentInstanceId = componentRiPair.getRight().getUniqueId();
        componentId = componentRiPair.getLeft().getUniqueId();
        artifactId = getLatestParentArtifactDataIdByArtifactUUID(artifactUUID, errorWrapper,
                componentInstanceId, ComponentTypeEnum.RESOURCE_INSTANCE);
    }
    if (errorWrapper.isEmpty()) {

        additionalParams.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceInstanceName);
        ArtifactOperation operation = ArtifactOperation.Delete;
        operation.setExternalApi(true);

        actionResult = handleArtifactRequest(componentInstanceId, userId, ComponentTypeEnum.RESOURCE_INSTANCE,
                operation, artifactId, null, origMd5, null, null, null, componentId,
                ComponentTypeEnum.findParamByType(componentType));

        if (actionResult.isRight()) {
            log.debug(
                    "Failed to upload artifact to component instance {} of component with type {} and uuid {}. Status is {}. ",
                    resourceInstanceName, componentType, componentUuid, actionResult.right().value());
            errorWrapper.setInnerElement(actionResult.right().value());
        }
    }
    if (errorWrapper.isEmpty()) {
        deleteArtifact = actionResult.left().value().left().value();
        updateAuditParametersWithArtifactDefinition(additionalParams, deleteArtifact);
        deleteArtifactResult = Either.left(deleteArtifact);
    } else {
        deleteArtifactResult = Either.right(errorWrapper.getInnerElement());
    }
    return deleteArtifactResult;
}

From source file:org.openecomp.sdc.be.components.impl.BaseBusinessLogic.java

protected Either<Boolean, ResponseFormat> validatePropertyDefaultValue(IComplexDefaultValue property,
        Map<String, DataTypeDefinition> dataTypes) {
    log.debug("validate property");
    String type = null;/*w ww . ja va 2 s. c o  m*/
    String innerType = null;
    if (!propertyOperation.isPropertyTypeValid(property)) {
        log.info("Invalid type for property");
        ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_TYPE,
                property.getType(), property.getName());
        return Either.right(responseFormat);
    }
    type = property.getType();
    if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
        ImmutablePair<String, Boolean> propertyInnerTypeValid = propertyOperation
                .isPropertyInnerTypeValid(property, dataTypes);
        innerType = propertyInnerTypeValid.getLeft();
        if (!propertyInnerTypeValid.getRight().booleanValue()) {
            log.info("Invalid inner type for property");
            ResponseFormat responseFormat = componentsUtils
                    .getResponseFormat(ActionStatus.INVALID_PROPERTY_INNER_TYPE, innerType, property.getName());
            return Either.right(responseFormat);
        }
    }
    if (!propertyOperation.isPropertyDefaultValueValid(property, dataTypes)) {
        log.info("Invalid default value for property");
        ResponseFormat responseFormat;
        if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
            responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE,
                    property.getName(), type, innerType, property.getDefaultValue());
        } else {
            responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_DEFAULT_VALUE,
                    property.getName(), type, property.getDefaultValue());
        }
        return Either.right(responseFormat);

    }
    return Either.left(true);
}

From source file:org.openecomp.sdc.be.components.impl.CompositionBusinessLogic.java

private void setRelativePosition(Entry<ImmutablePair<Double, Double>, ComponentInstance> entry) {
    int xCenter = CANVAS_WIDTH / 2;
    int yCenter = CANVAS_HEIGHT / 2;

    ImmutablePair<Double, Double> matrixPosition = entry.getKey();
    ComponentInstance componentInstance = entry.getValue();
    componentInstance/*from w  ww.  j av a 2  s  .c om*/
            .setPosX(calculateCompositionPosition(xCenter, matrixPosition.getLeft(), componentInstance));
    componentInstance
            .setPosY(calculateCompositionPosition(yCenter, matrixPosition.getRight(), componentInstance));
}

From source file:org.openecomp.sdc.be.components.impl.CompositionBusinessLogic.java

private void buildCirclePatternForOneGroupOfCps(ImmutablePair<Double, Double> vfcLocation,
        List<ComponentInstance> cpsGroup,
        Map<ImmutablePair<Double, Double>, ComponentInstance> componentInstLocations) {
    final int numberOfCps = cpsGroup.size();
    double angleBetweenCps = (!cpsGroup.isEmpty()) ? Math.toRadians(360) / numberOfCps : 0;
    double currentAngle = 0;
    Double xCenter = vfcLocation.getLeft();
    Double yCenter = vfcLocation.getRight();
    for (ComponentInstance currCp : cpsGroup) {
        double cpXposition = xCenter + CompositionBusinessLogic.CP_RADIUS_FACTOR * Math.cos(currentAngle);
        double cpYposition = yCenter + CompositionBusinessLogic.CP_RADIUS_FACTOR * Math.sin(currentAngle);
        componentInstLocations.put(new ImmutablePair<Double, Double>(cpXposition, cpYposition), currCp);
        currentAngle += angleBetweenCps;
    }//w ww  .  ja  va2 s  .  c  o  m

}

From source file:org.openecomp.sdc.be.components.impl.CompositionBusinessLogic.java

private ImmutablePair<Double, Double> getRelativeElementLocation(ImmutablePair<Double, Double> currElement,
        RelativePosition relativeLocation) {
    ImmutablePair<Double, Double> relativeElementPosition;
    switch (relativeLocation) {

    case LEFT: {/*w w  w.j av  a2  s.  co  m*/
        relativeElementPosition = new ImmutablePair<Double, Double>(currElement.getLeft() - 1,
                currElement.getRight());
        break;
    }
    case RIGHT: {
        relativeElementPosition = new ImmutablePair<Double, Double>(currElement.getLeft() + 1,
                currElement.getRight());
        break;
    }
    case UP: {
        relativeElementPosition = new ImmutablePair<Double, Double>(currElement.getLeft(),
                currElement.getRight() + 1);
        break;
    }
    case DOWN: {
        relativeElementPosition = new ImmutablePair<Double, Double>(currElement.getLeft(),
                currElement.getRight() - 1);
        break;
    }
    default: {
        throw new UnsupportedOperationException();
    }
    }
    return relativeElementPosition;
}

From source file:org.openecomp.sdc.be.components.impl.ResourceBusinessLogic.java

public Either<Boolean, ResponseFormat> validatePropertiesDefaultValues(Resource resource) {
    log.debug("validate resource properties default values");
    Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
    List<PropertyDefinition> properties = resource.getProperties();
    String type = null;//w w w.  j  av a 2s  .c  om
    String innerType = null;
    if (properties != null) {
        for (PropertyDefinition property : properties) {
            if (!propertyOperation.isPropertyTypeValid(property)) {
                log.info("Invalid type for property");
                ResponseFormat responseFormat = componentsUtils.getResponseFormat(
                        ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName());
                eitherResult = Either.right(responseFormat);
                break;
            }

            Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(
                    applicationDataTypeCache);
            if (allDataTypes.isRight()) {
                return Either.right(allDataTypes.right().value());
            }

            type = property.getType();
            if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
                ImmutablePair<String, Boolean> propertyInnerTypeValid = propertyOperation
                        .isPropertyInnerTypeValid(property, allDataTypes.left().value());
                innerType = propertyInnerTypeValid.getLeft();
                if (!propertyInnerTypeValid.getRight().booleanValue()) {
                    log.info("Invalid inner type for property");
                    ResponseFormat responseFormat = componentsUtils.getResponseFormat(
                            ActionStatus.INVALID_PROPERTY_INNER_TYPE, innerType, property.getName());
                    eitherResult = Either.right(responseFormat);
                    break;
                }
            }

            if (!propertyOperation.isPropertyDefaultValueValid(property, allDataTypes.left().value())) {
                log.info("Invalid default value for property");
                ResponseFormat responseFormat;
                if (type.equals(ToscaPropertyType.LIST.getType())
                        || type.equals(ToscaPropertyType.MAP.getType())) {
                    responseFormat = componentsUtils.getResponseFormat(
                            ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE, property.getName(), type, innerType,
                            property.getDefaultValue());
                } else {
                    responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_DEFAULT_VALUE,
                            property.getName(), type, property.getDefaultValue());
                }
                eitherResult = Either.right(responseFormat);
                break;

            }
        }
    }
    return eitherResult;
}