summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.cds/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'models-interactions/model-actors/actor.cds/src/main/java/org')
-rw-r--r--models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java99
-rw-r--r--models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/properties/GrcpOperationResourceVnfProperties.java83
-rw-r--r--models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/properties/GrpcOperationPnfProperties.java68
-rw-r--r--models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/properties/GrpcOperationProperties.java78
-rw-r--r--models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/properties/GrpcOperationTargetVnfProperties.java61
5 files changed, 297 insertions, 92 deletions
diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java
index 87eaa9572..87d94038f 100644
--- a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java
+++ b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Bell Canada. All rights reserved.
- * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020-2022 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,27 +26,22 @@ import com.google.protobuf.Struct;
import com.google.protobuf.util.JsonFormat;
import java.util.Collections;
import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
-import java.util.function.Supplier;
import lombok.Getter;
-import org.onap.aai.domain.yang.GenericVnf;
-import org.onap.aai.domain.yang.ServiceInstance;
import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
import org.onap.policy.cds.client.CdsProcessorGrpcClient;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.controlloop.actor.cds.constants.CdsActorConstants;
+import org.onap.policy.controlloop.actor.cds.properties.GrpcOperationProperties;
import org.onap.policy.controlloop.actor.cds.request.CdsActionRequest;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
-import org.onap.policy.controlloop.actorserviceprovider.TargetType;
-import org.onap.policy.controlloop.actorserviceprovider.Util;
import org.onap.policy.controlloop.actorserviceprovider.impl.OperationPartial;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.pipeline.PipelineControllerFuture;
@@ -60,10 +55,6 @@ public class GrpcOperation extends OperationPartial {
public static final String NAME = "any";
- private static final String AAI_PNF_PREFIX = "pnf.";
- private static final String AAI_VNF_ID_KEY = "generic-vnf.vnf-id";
- private static final String AAI_SERVICE_INSTANCE_ID_KEY = "service-instance.service-instance-id";
-
private CdsProcessorGrpcClient client;
/**
@@ -72,24 +63,9 @@ public class GrpcOperation extends OperationPartial {
private final GrpcConfig config;
/**
- * Function to convert the A&AI data associated with the target type.
+ * Operation properties.
*/
- private final Supplier<Map<String, String>> aaiConverter;
-
-
- // @formatter:off
- private static final List<String> PNF_PROPERTY_NAMES = List.of(
- OperationProperties.AAI_PNF,
- OperationProperties.EVENT_ADDITIONAL_PARAMS,
- OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES);
-
-
- private static final List<String> VNF_PROPERTY_NAMES = List.of(
- OperationProperties.AAI_RESOURCE_VNF,
- OperationProperties.AAI_SERVICE,
- OperationProperties.EVENT_ADDITIONAL_PARAMS,
- OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES);
- // @formatter:on
+ private final GrpcOperationProperties opProperties;
/**
* Constructs the object.
@@ -100,17 +76,12 @@ public class GrpcOperation extends OperationPartial {
public GrpcOperation(ControlLoopOperationParams params, GrpcConfig config) {
super(params, config, Collections.emptyList());
this.config = config;
-
- if (TargetType.PNF.equals(params.getTargetType())) {
- aaiConverter = this::convertPnfToAaiProperties;
- } else {
- aaiConverter = this::convertVnfToAaiProperties;
- }
+ this.opProperties = GrpcOperationProperties.build(params);
}
@Override
public List<String> getPropertyNames() {
- return (TargetType.PNF.equals(params.getTargetType()) ? PNF_PROPERTY_NAMES : VNF_PROPERTY_NAMES);
+ return this.opProperties.getPropertyNames();
}
/**
@@ -121,62 +92,6 @@ public class GrpcOperation extends OperationPartial {
return (timeoutSec == null || timeoutSec == 0 ? config.getTimeoutMs() : super.getTimeoutMs(timeoutSec));
}
- /**
- * Converts the A&AI PNF data to a map suitable for passing via the "aaiProperties"
- * field in the CDS request.
- *
- * @return a map of the PNF data
- */
- private Map<String, String> convertPnfToAaiProperties() {
- Map<String, String> result = getProperty(OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES);
- if (result != null) {
- return result;
- }
-
- // convert PNF data to a Map
- Object pnfData = getRequiredProperty(OperationProperties.AAI_PNF, "PNF");
- Map<String, Object> source = Util.translateToMap(getFullName(), pnfData);
-
- result = new LinkedHashMap<>();
-
- for (Entry<String, Object> ent : source.entrySet()) {
- result.put(AAI_PNF_PREFIX + ent.getKey(), ent.getValue().toString());
- }
-
- return result;
- }
-
- /**
- * Converts the A&AI VNF data to a map suitable for passing via the
- * "aaiProperties" field in the CDS request.
- *
- * @return a map of the VNF data
- */
- private Map<String, String> convertVnfToAaiProperties() {
- Map<String, String> result = getProperty(OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES);
- if (result != null) {
- return result;
- }
-
- result = new LinkedHashMap<>();
-
- result.put(AAI_SERVICE_INSTANCE_ID_KEY, getServiceInstanceId());
- result.put(AAI_VNF_ID_KEY, getVnfId());
-
- return result;
- }
-
- protected String getServiceInstanceId() {
- var serviceInstance = (ServiceInstance) getRequiredProperty(OperationProperties.AAI_SERVICE,
- "Target service instance");
- return serviceInstance.getServiceInstanceId();
- }
-
- protected String getVnfId() {
- var genericVnf = (GenericVnf) getRequiredProperty(OperationProperties.AAI_RESOURCE_VNF, "Target generic vnf");
- return genericVnf.getVnfId();
- }
-
@Override
public void generateSubRequestId(int attempt) {
setSubRequestId("0");
@@ -251,7 +166,7 @@ public class GrpcOperation extends OperationPartial {
//
// Note: that is a future enhancement. For now, the actor is hard-coded to
// use the A&AI query result specific to the target type
- request.setAaiProperties(aaiConverter.get());
+ request.setAaiProperties(opProperties.convertToAaiProperties(this));
// Inject any additional event parameters that may be present in the onset event
Map<String, String> additionalParams = getProperty(OperationProperties.EVENT_ADDITIONAL_PARAMS);
diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/properties/GrcpOperationResourceVnfProperties.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/properties/GrcpOperationResourceVnfProperties.java
new file mode 100644
index 000000000..5fcd30721
--- /dev/null
+++ b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/properties/GrcpOperationResourceVnfProperties.java
@@ -0,0 +1,83 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.controlloop.actor.cds.properties;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.aai.domain.yang.ServiceInstance;
+import org.onap.policy.controlloop.actor.cds.GrpcOperation;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
+
+/**
+ * VNF with target entities properties.
+ */
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class GrcpOperationResourceVnfProperties extends GrpcOperationProperties {
+
+ // @formatter:off
+ protected static final List<String> VNF_PROPERTY_NAMES = List.of(
+ OperationProperties.AAI_RESOURCE_VNF,
+ OperationProperties.AAI_SERVICE,
+ OperationProperties.EVENT_ADDITIONAL_PARAMS,
+ OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES);
+ // @formatter:on
+
+ @Override
+ public List<String> getPropertyNames() {
+ return VNF_PROPERTY_NAMES;
+ }
+
+ @Override
+ public Map<String, String> convertToAaiProperties(GrpcOperation operation) {
+ Map<String, String> result = operation.getProperty(OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES);
+ if (result != null) {
+ return result;
+ }
+
+ result = new LinkedHashMap<>();
+ result.put(AAI_SERVICE_INSTANCE_ID_KEY, getServiceInstanceId(operation));
+ result.put(AAI_VNF_ID_KEY, getVnfId(operation));
+ return result;
+ }
+
+ /**
+ * Get the service instance id from the required operation property.
+ */
+ public String getServiceInstanceId(GrpcOperation operation) {
+ var serviceInstance =
+ (ServiceInstance) operation.getRequiredProperty(OperationProperties.AAI_SERVICE,
+ "Target service instance");
+ return serviceInstance.getServiceInstanceId();
+ }
+
+ /**
+ * Get the vnf id from the required property.
+ */
+ public String getVnfId(GrpcOperation operation) {
+ var genericVnf =
+ (GenericVnf) operation.getRequiredProperty(OperationProperties.AAI_RESOURCE_VNF, "Target generic vnf");
+ return genericVnf.getVnfId();
+ }
+}
diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/properties/GrpcOperationPnfProperties.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/properties/GrpcOperationPnfProperties.java
new file mode 100644
index 000000000..4d9316a8e
--- /dev/null
+++ b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/properties/GrpcOperationPnfProperties.java
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.controlloop.actor.cds.properties;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.onap.policy.controlloop.actor.cds.GrpcOperation;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
+import org.onap.policy.controlloop.actorserviceprovider.Util;
+
+/**
+ * GRPC Operation with PNF properties.
+ */
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class GrpcOperationPnfProperties extends GrpcOperationProperties {
+
+ // @formatter:off
+ protected static final List<String> PNF_PROPERTY_NAMES = List.of(
+ OperationProperties.AAI_PNF,
+ OperationProperties.EVENT_ADDITIONAL_PARAMS,
+ OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES);
+ // @formatter:on
+
+ @Override
+ public List<String> getPropertyNames() {
+ return PNF_PROPERTY_NAMES;
+ }
+
+ @Override
+ public Map<String, String> convertToAaiProperties(GrpcOperation operation) {
+ Map<String, String> result = operation.getProperty(OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES);
+ if (result != null) {
+ return result;
+ }
+
+ Object pnfData = operation.getRequiredProperty(OperationProperties.AAI_PNF, "PNF");
+ Map<String, Object> source = Util.translateToMap(operation.getFullName(), pnfData);
+
+ result = new LinkedHashMap<>();
+
+ for (Map.Entry<String, Object> ent : source.entrySet()) {
+ result.put(AAI_PNF_PREFIX + ent.getKey(), ent.getValue().toString());
+ }
+
+ return result;
+ }
+}
diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/properties/GrpcOperationProperties.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/properties/GrpcOperationProperties.java
new file mode 100644
index 000000000..fd49ea52c
--- /dev/null
+++ b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/properties/GrpcOperationProperties.java
@@ -0,0 +1,78 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.controlloop.actor.cds.properties;
+
+import java.util.List;
+import java.util.Map;
+import lombok.Data;
+import org.onap.policy.controlloop.actor.cds.GrpcOperation;
+import org.onap.policy.controlloop.actorserviceprovider.TargetType;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.util.CollectionUtils;
+
+/**
+ * GRPC Operation Base Class.
+ */
+@Data
+public abstract class GrpcOperationProperties {
+ protected static final String AAI_PNF_PREFIX = "pnf.";
+
+ /**
+ * AAI VNF Identifier.
+ */
+ public static final String AAI_VNF_ID_KEY = "generic-vnf.vnf-id";
+
+ /**
+ * AAI Service Instance Identifier.
+ */
+ public static final String AAI_SERVICE_INSTANCE_ID_KEY = "service-instance.service-instance-id";
+
+ private static final Logger logger = LoggerFactory.getLogger(GrpcOperationProperties.class);
+
+ /**
+ * Build the appropriate GrpcOperation object depending on the target type.
+ */
+ public static GrpcOperationProperties build(ControlLoopOperationParams params) {
+ if (TargetType.PNF.equals(params.getTargetType())) {
+ return new GrpcOperationPnfProperties();
+ }
+
+ // assume VNF processing for backwards compatibility with istanbul
+
+ if (!TargetType.VNF.equals(params.getTargetType())) {
+ logger.warn("Unexpected target type, build VNF-like operation properties");
+ }
+
+ return CollectionUtils.isEmpty(params.getTargetEntityIds())
+ ? new GrpcOperationTargetVnfProperties()
+ : new GrcpOperationResourceVnfProperties();
+ }
+
+ /**
+ * Get the property names.
+ */
+ public abstract List<String> getPropertyNames();
+
+ /**
+ * Convert to the AAI properties.
+ */
+ public abstract Map<String, String> convertToAaiProperties(GrpcOperation operation);
+}
diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/properties/GrpcOperationTargetVnfProperties.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/properties/GrpcOperationTargetVnfProperties.java
new file mode 100644
index 000000000..6c5a97d36
--- /dev/null
+++ b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/properties/GrpcOperationTargetVnfProperties.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.controlloop.actor.cds.properties;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.onap.policy.controlloop.actor.cds.GrpcOperation;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
+
+/**
+ * GRPC Operation with Target VNF properties.
+ */
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class GrpcOperationTargetVnfProperties extends GrpcOperationProperties {
+
+ // @formatter:off
+ protected static final List<String> VNF_PROPERTY_NAMES = List.of(
+ OperationProperties.AAI_TARGET_ENTITY,
+ OperationProperties.EVENT_ADDITIONAL_PARAMS,
+ OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES);
+ // @formatter:on
+
+ @Override
+ public List<String> getPropertyNames() {
+ return VNF_PROPERTY_NAMES;
+ }
+
+ @Override
+ public Map<String, String> convertToAaiProperties(GrpcOperation operation) {
+ Map<String, String> result = operation.getProperty(OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES);
+ if (result != null) {
+ return result;
+ }
+
+ result = new LinkedHashMap<>();
+ result.put(AAI_VNF_ID_KEY,
+ operation.getRequiredProperty(OperationProperties.AAI_TARGET_ENTITY, "vnf id"));
+ return result;
+ }
+}