aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-rest
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-rest')
-rw-r--r--cps-ncmp-rest/docs/openapi/components.yaml34
-rwxr-xr-xcps-ncmp-rest/docs/openapi/ncmp.yml58
-rwxr-xr-xcps-ncmp-rest/docs/openapi/openapi.yml6
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java7
-rwxr-xr-xcps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java79
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapper.java (renamed from cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/RestOutputCmHandleStateMapper.java)9
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy17
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy104
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy4
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapperTest.groovy (renamed from cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/RestOutputCmHandleStateMapperTest.groovy)14
-rw-r--r--cps-ncmp-rest/src/test/resources/application.yml3
11 files changed, 280 insertions, 55 deletions
diff --git a/cps-ncmp-rest/docs/openapi/components.yaml b/cps-ncmp-rest/docs/openapi/components.yaml
index 248b1daa6..8249a7a3d 100644
--- a/cps-ncmp-rest/docs/openapi/components.yaml
+++ b/cps-ncmp-rest/docs/openapi/components.yaml
@@ -145,6 +145,30 @@ components:
type: string
example: my-module-revision
+ RestModuleDefinition:
+ type: object
+ title: Module definitions
+ properties:
+ moduleName:
+ type: string
+ example: my-module-name
+ revision:
+ type: string
+ example: 2020-09-15
+ content:
+ type: string
+ example: |
+ module stores {
+ yang-version 1.1;
+ namespace "org:onap:ccsdk:sample";
+ prefix book-store;
+ revision "2020-09-15" {
+ description
+ "Sample Model";
+ }
+ }
+
+
CmHandleQueryParameters:
type: object
title: Cm Handle query parameters for executing cm handle search
@@ -209,7 +233,7 @@ components:
publicCmHandleProperties:
$ref: '#/components/schemas/CmHandlePublicProperties'
state:
- $ref: '#/components/schemas/RestOutputCmHandleState'
+ $ref: '#/components/schemas/CmHandleCompositeState'
CmHandlePublicProperties:
type: array
items:
@@ -217,7 +241,7 @@ components:
additionalProperties:
type: string
example: Book Type
- RestOutputCmHandleState:
+ CmHandleCompositeState:
type: object
properties:
cmHandleState:
@@ -268,6 +292,12 @@ components:
publicCmHandleProperties:
$ref: '#/components/schemas/CmHandlePublicProperties'
+ RestOutputCmHandleCompositeState:
+ type: object
+ properties:
+ state:
+ $ref: '#/components/schemas/CmHandleCompositeState'
+
examples:
dataSampleRequest:
summary: Sample request
diff --git a/cps-ncmp-rest/docs/openapi/ncmp.yml b/cps-ncmp-rest/docs/openapi/ncmp.yml
index 3259032f2..aaf0d6a1a 100755
--- a/cps-ncmp-rest/docs/openapi/ncmp.yml
+++ b/cps-ncmp-rest/docs/openapi/ncmp.yml
@@ -246,6 +246,31 @@ fetchModuleReferencesByCmHandle:
500:
$ref: 'components.yaml#/components/responses/InternalServerError'
+fetchModuleDefinitionsByCmHandle:
+ get:
+ description: Fetch all module definitions (name, revision, yang resource) for a given cm handle
+ tags:
+ - network-cm-proxy
+ summary: Fetch all module definitions (name, revision, yang resource) for a given cm handle
+ operationId: getModuleDefinitionsByCmHandleId
+ parameters:
+ - $ref: 'components.yaml#/components/parameters/cmHandleInPath'
+ responses:
+ 200:
+ description: OK
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ $ref: 'components.yaml#/components/schemas/RestModuleDefinition'
+ 401:
+ $ref: 'components.yaml#/components/responses/Unauthorized'
+ 403:
+ $ref: 'components.yaml#/components/responses/Forbidden'
+ 500:
+ $ref: 'components.yaml#/components/responses/InternalServerError'
+
searchCmHandles:
post:
description: Execute cm handle query search, to be included in the result a cm-handle must fulfill ALL the conditions listed here, if one of the given module names does not exists, return with an empty collection.
@@ -293,6 +318,10 @@ retrieveCmHandleDetailsById:
application/json:
schema:
$ref: 'components.yaml#/components/schemas/RestOutputCmHandle'
+ 400:
+ $ref: 'components.yaml#/components/responses/BadRequest'
+ 401:
+ $ref: 'components.yaml#/components/responses/Unauthorized'
404:
$ref: 'components.yaml#/components/responses/NotFound'
500:
@@ -314,6 +343,35 @@ getCmHandlePropertiesById:
application/json:
schema:
$ref: 'components.yaml#/components/schemas/RestOutputCmHandlePublicProperties'
+ 400:
+ $ref: 'components.yaml#/components/responses/BadRequest'
+ 401:
+ $ref: 'components.yaml#/components/responses/Unauthorized'
+ 404:
+ $ref: 'components.yaml#/components/responses/NotFound'
+ 500:
+ $ref: 'components.yaml#/components/responses/InternalServerError'
+
+getCmHandleStateById:
+ get:
+ description: Get CM handle state by cm handle id
+ tags:
+ - network-cm-proxy
+ summary: Get CM handle state
+ operationId: getCmHandleStateByCmHandleId
+ parameters:
+ - $ref: 'components.yaml#/components/parameters/cmHandleInPath'
+ responses:
+ 200:
+ description: OK
+ content:
+ application/json:
+ schema:
+ $ref: 'components.yaml#/components/schemas/RestOutputCmHandleCompositeState'
+ 400:
+ $ref: 'components.yaml#/components/responses/BadRequest'
+ 401:
+ $ref: 'components.yaml#/components/responses/Unauthorized'
404:
$ref: 'components.yaml#/components/responses/NotFound'
500:
diff --git a/cps-ncmp-rest/docs/openapi/openapi.yml b/cps-ncmp-rest/docs/openapi/openapi.yml
index 81ebf05ed..35be59a38 100755
--- a/cps-ncmp-rest/docs/openapi/openapi.yml
+++ b/cps-ncmp-rest/docs/openapi/openapi.yml
@@ -35,6 +35,9 @@ paths:
/v1/ch/{cm-handle}/modules:
$ref: 'ncmp.yml#/fetchModuleReferencesByCmHandle'
+ /v1/ch/{cm-handle}/modules/definitions:
+ $ref: 'ncmp.yml#/fetchModuleDefinitionsByCmHandle'
+
/v1/ch/searches:
$ref: 'ncmp.yml#/searchCmHandles'
@@ -46,3 +49,6 @@ paths:
/v1/ch/id-searches:
$ref: 'ncmp.yml#/searchCmHandleIds'
+
+ /v1/ch/{cm-handle}/state:
+ $ref: 'ncmp.yml#/getCmHandleStateById'
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java
index a9ec863d5..118fa4526 100644
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java
@@ -20,6 +20,7 @@
package org.onap.cps.ncmp.rest.controller;
+import org.mapstruct.InheritConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueCheckStrategy;
@@ -28,7 +29,9 @@ import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration;
import org.onap.cps.ncmp.rest.model.RestInputCmHandle;
+import org.onap.cps.ncmp.rest.model.RestModuleDefinition;
import org.onap.cps.ncmp.rest.model.RestModuleReference;
+import org.onap.cps.spi.model.ModuleDefinition;
import org.onap.cps.spi.model.ModuleReference;
@Mapper(componentModel = "spring")
@@ -52,4 +55,8 @@ public interface NcmpRestInputMapper {
RestModuleReference toRestModuleReference(
final ModuleReference moduleReference);
+
+ @InheritConfiguration(name = "toRestModuleReference")
+ RestModuleDefinition toRestModuleDefinition(
+ final ModuleDefinition moduleDefinition);
} \ No newline at end of file
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
index fb234ef71..33355475d 100755
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
@@ -28,7 +28,6 @@ import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum
import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.PATCH;
import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.UPDATE;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -40,15 +39,18 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
import org.onap.cps.ncmp.api.impl.exception.InvalidTopicException;
+import org.onap.cps.ncmp.api.inventory.CompositeState;
import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi;
import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor;
-import org.onap.cps.ncmp.rest.mapper.RestOutputCmHandleStateMapper;
+import org.onap.cps.ncmp.rest.mapper.CmHandleStateMapper;
import org.onap.cps.ncmp.rest.model.CmHandlePublicProperties;
import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters;
+import org.onap.cps.ncmp.rest.model.RestModuleDefinition;
import org.onap.cps.ncmp.rest.model.RestModuleReference;
import org.onap.cps.ncmp.rest.model.RestOutputCmHandle;
+import org.onap.cps.ncmp.rest.model.RestOutputCmHandleCompositeState;
import org.onap.cps.ncmp.rest.model.RestOutputCmHandlePublicProperties;
import org.onap.cps.ncmp.rest.util.DeprecationHelper;
import org.onap.cps.utils.CpsValidator;
@@ -73,11 +75,12 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
private final DeprecationHelper deprecationHelper;
private final NcmpRestInputMapper ncmpRestInputMapper;
- private final RestOutputCmHandleStateMapper restOutputCmHandleStateMapper;
+ private final CmHandleStateMapper cmHandleStateMapper;
private final CpsNcmpTaskExecutor cpsNcmpTaskExecutor;
-
@Value("${notification.async.executor.time-out-value-in-ms:2000}")
private int timeOutInMilliSeconds;
+ @Value("${notification.enabled:true}")
+ private boolean asyncEnabled;
/**
* Get resource data from operational datastore.
@@ -93,15 +96,18 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
final @NotNull @Valid String resourceIdentifier,
final @Valid String optionsParamInQuery,
final @Valid String topicParamInQuery) {
- if (isValidTopic(topicParamInQuery)) {
+ if (asyncEnabled && isValidTopic(topicParamInQuery)) {
final String requestId = UUID.randomUUID().toString();
+ log.info("Received Async passthrough-operational request with id {}", requestId);
cpsNcmpTaskExecutor.executeTask(() ->
- networkCmProxyDataService.getResourceDataOperationalForCmHandle(
- cmHandle, resourceIdentifier, optionsParamInQuery, topicParamInQuery,
- requestId
- ), timeOutInMilliSeconds
+ networkCmProxyDataService.getResourceDataOperationalForCmHandle(
+ cmHandle, resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId
+ ), timeOutInMilliSeconds
);
- return acknowledgeAsyncRequest(requestId);
+ return ResponseEntity.ok(Map.of("requestId", requestId));
+ } else {
+ log.warn("Asynchronous messaging is currently disabled for passthrough-operational."
+ + " Will use synchronous operation.");
}
final Object responseObject = networkCmProxyDataService.getResourceDataOperationalForCmHandle(
@@ -124,15 +130,18 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
final @NotNull @Valid String resourceIdentifier,
final @Valid String optionsParamInQuery,
final @Valid String topicParamInQuery) {
- if (isValidTopic(topicParamInQuery)) {
- final String resourceDataRequestId = UUID.randomUUID().toString();
+ if (asyncEnabled && isValidTopic(topicParamInQuery)) {
+ final String requestId = UUID.randomUUID().toString();
+ log.info("Received Async passthrough-running request with id {}", requestId);
cpsNcmpTaskExecutor.executeTask(() ->
networkCmProxyDataService.getResourceDataPassThroughRunningForCmHandle(
- cmHandle, resourceIdentifier, optionsParamInQuery, topicParamInQuery,
- resourceDataRequestId
+ cmHandle, resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId
), timeOutInMilliSeconds
);
- return acknowledgeAsyncRequest(resourceDataRequestId);
+ return ResponseEntity.ok(Map.of("requestId", requestId));
+ } else {
+ log.warn("Asynchronous messaging is currently disabled for passthrough-running."
+ + " Will use synchronous operation.");
}
final Object responseObject = networkCmProxyDataService.getResourceDataPassThroughRunningForCmHandle(
@@ -253,7 +262,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
/**
* Get Cm Handle Properties by Cm Handle Id.
* @param cmHandleId cm-handle identifier
- * @return cm handle and its properties
+ * @return cm handle properties
*/
@Override
public ResponseEntity<RestOutputCmHandlePublicProperties> getCmHandlePublicPropertiesByCmHandleId(
@@ -267,6 +276,36 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
}
/**
+ * Get Cm Handle State by Cm Handle Id.
+ * @param cmHandleId cm-handle identifier
+ * @return cm handle state
+ */
+ @Override
+ public ResponseEntity<RestOutputCmHandleCompositeState> getCmHandleStateByCmHandleId(
+ final String cmHandleId) {
+ final CompositeState cmHandleState = networkCmProxyDataService.getCmHandleCompositeState(cmHandleId);
+ final RestOutputCmHandleCompositeState restOutputCmHandleCompositeState =
+ new RestOutputCmHandleCompositeState();
+ restOutputCmHandleCompositeState.setState(cmHandleStateMapper.toCmHandleCompositeState(cmHandleState));
+ return ResponseEntity.ok(restOutputCmHandleCompositeState);
+ }
+
+ /**
+ * Return module definitions for a cm handle.
+ *
+ * @param cmHandleId cm-handle identifier
+ * @return list of module definitions (module name, revision, yang resource content)
+ */
+ @Override
+ public ResponseEntity<List<RestModuleDefinition>> getModuleDefinitionsByCmHandleId(final String cmHandleId) {
+ final List<RestModuleDefinition> restModuleDefinitions =
+ networkCmProxyDataService.getModuleDefinitionsByCmHandleId(cmHandleId).stream()
+ .map(ncmpRestInputMapper::toRestModuleDefinition)
+ .collect(Collectors.toList());
+ return new ResponseEntity<>(restModuleDefinitions, HttpStatus.OK);
+ }
+
+ /**
* Return module references for a cm handle.
*
* @param cmHandle the cm handle
@@ -286,7 +325,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
restOutputCmHandle.setCmHandle(ncmpServiceCmHandle.getCmHandleId());
cmHandlePublicProperties.add(ncmpServiceCmHandle.getPublicProperties());
restOutputCmHandle.setPublicCmHandleProperties(cmHandlePublicProperties);
- restOutputCmHandle.setState(restOutputCmHandleStateMapper.toRestOutputCmHandleState(
+ restOutputCmHandle.setState(cmHandleStateMapper.toCmHandleCompositeState(
ncmpServiceCmHandle.getCompositeState()));
return restOutputCmHandle;
}
@@ -301,11 +340,5 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
throw new InvalidTopicException("Topic name " + topicName + " is invalid", "invalid topic");
}
- private ResponseEntity<Object> acknowledgeAsyncRequest(final String requestId) {
- final Map<String, Object> acknowledgeData = new HashMap<>(1);
- acknowledgeData.put("requestId", requestId);
- return ResponseEntity.ok(acknowledgeData);
- }
-
}
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/RestOutputCmHandleStateMapper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapper.java
index afad1098c..ca109d649 100644
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/RestOutputCmHandleStateMapper.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapper.java
@@ -26,17 +26,17 @@ import org.mapstruct.Named;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.NullValuePropertyMappingStrategy;
import org.onap.cps.ncmp.api.inventory.CompositeState;
+import org.onap.cps.ncmp.rest.model.CmHandleCompositeState;
import org.onap.cps.ncmp.rest.model.DataStores;
-import org.onap.cps.ncmp.rest.model.RestOutputCmHandleState;
import org.onap.cps.ncmp.rest.model.SyncState;
@Mapper(componentModel = "spring", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT)
-public interface RestOutputCmHandleStateMapper {
+public interface CmHandleStateMapper {
@Mapping(target = "dataSyncState", source = "dataStores", qualifiedByName = "dataStoreToDataSyncState")
@Mapping(target = "lockReason.reason", source = "lockReason.lockReasonCategory")
- RestOutputCmHandleState toRestOutputCmHandleState(CompositeState compositeState);
+ CmHandleCompositeState toCmHandleCompositeState(CompositeState compositeState);
/**
* Convert from CompositeState datastore to RestOutput Datastores.
@@ -55,7 +55,8 @@ public interface RestOutputCmHandleStateMapper {
if (compositeStateDataStore.getOperationalDataStore() != null) {
final SyncState operationalSyncState = new SyncState();
- operationalSyncState.setState(compositeStateDataStore.getOperationalDataStore().getSyncState().name());
+ operationalSyncState.setState(compositeStateDataStore.getOperationalDataStore()
+ .getDataStoreSyncState().name());
operationalSyncState.setLastSyncTime(compositeStateDataStore.getOperationalDataStore().getLastSyncTime());
dataStores.setOperational(operationalSyncState);
}
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy
index bb762080d..cd3770eb8 100644
--- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy
+++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy
@@ -24,7 +24,9 @@ import org.mapstruct.factory.Mappers
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration
import org.onap.cps.ncmp.rest.model.RestInputCmHandle
+import org.onap.cps.ncmp.rest.model.RestModuleDefinition
import org.onap.cps.ncmp.rest.model.RestModuleReference
+import org.onap.cps.spi.model.ModuleDefinition
import org.onap.cps.spi.model.ModuleReference
import spock.lang.Specification
@@ -87,4 +89,19 @@ class NcmpRestInputMapperSpec extends Specification {
then: 'the result is of the correct class RestModuleReference'
result.class == RestModuleReference.class
}
+
+ def 'Convert a ModuleDefinition to a RestModuleDefinition'() {
+ given: 'a ModuleDefinition'
+ def moduleDefinition = new ModuleDefinition('moduleName','revision', 'content')
+ when: 'toRestModuleDefinition is called'
+ def result = objectUnderTest.toRestModuleDefinition(moduleDefinition)
+ then: 'the result is of the correct class RestModuleDefinition'
+ result.class == RestModuleDefinition.class
+ and: 'all contents are mapped correctly'
+ result.toString()=='class RestModuleDefinition {\n' +
+ ' moduleName: moduleName\n' +
+ ' revision: revision\n' +
+ ' content: content\n' +
+ '}'
+ }
}
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
index 71258102e..729df9ce4 100644
--- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
+++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
@@ -26,11 +26,13 @@ package org.onap.cps.ncmp.rest.controller
import org.mapstruct.factory.Mappers
import org.onap.cps.ncmp.api.inventory.CmHandleState
import org.onap.cps.ncmp.api.inventory.CompositeState
-import org.onap.cps.ncmp.api.inventory.SyncState
+import org.onap.cps.ncmp.api.inventory.LockReasonCategory
+import org.onap.cps.ncmp.api.inventory.DataStoreSyncState
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
-import org.onap.cps.ncmp.rest.mapper.RestOutputCmHandleStateMapper
+import org.onap.cps.ncmp.rest.mapper.CmHandleStateMapper
import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor
import org.onap.cps.ncmp.rest.util.DeprecationHelper
+import org.onap.cps.spi.model.ModuleDefinition
import spock.lang.Shared
import java.time.OffsetDateTime
@@ -40,7 +42,6 @@ import java.time.format.DateTimeFormatter
import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.PATCH
import static org.onap.cps.ncmp.api.inventory.CompositeState.DataStores
import static org.onap.cps.ncmp.api.inventory.CompositeState.Operational
-import static org.onap.cps.ncmp.api.inventory.CompositeState.Running
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch
@@ -83,7 +84,7 @@ class NetworkCmProxyControllerSpec extends Specification {
NcmpRestInputMapper ncmpRestInputMapper = Mappers.getMapper(NcmpRestInputMapper)
@SpringBean
- RestOutputCmHandleStateMapper restOutputCmHandleStateMapper = Mappers.getMapper(RestOutputCmHandleStateMapper)
+ CmHandleStateMapper cmHandleStateMapper = Mappers.getMapper(CmHandleStateMapper)
@SpringBean
CpsNcmpTaskExecutor spiedCpsTaskExecutor = Spy()
@@ -262,24 +263,27 @@ class NetworkCmProxyControllerSpec extends Specification {
response.contentAsString == '[{"cmHandle":"some-cmhandle-id1","publicCmHandleProperties":[{"color":"yellow"}],"state":null},{"cmHandle":"some-cmhandle-id2","publicCmHandleProperties":[{"color":"green"}],"state":null}]'
}
- def 'Get Cm Handle details by Cm Handle id.'() {
+ def 'Get complete Cm Handle details by Cm Handle id.'() {
given: 'an endpoint and a cm handle'
def cmHandleDetailsEndpoint = "$ncmpBasePathV1/ch/some-cm-handle"
and: 'an existing ncmp service cm handle'
- def compositeState = new CompositeState(cmHandleState: CmHandleState.ADVISED,
- lastUpdateTime: formattedDateAndTime.toString(),
- dataStores: dataStores())
- def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: 'some-cm-handle', compositeState: compositeState)
+ def cmHandleId = 'some-cm-handle'
+ def dmiProperties = [ prop:'some DMI property' ]
+ def publicProperties = [ "public prop":'some public property' ]
+ def compositeState = compositeStateTestObject()
+ def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, dmiProperties: dmiProperties, publicProperties: publicProperties, compositeState: compositeState)
and: 'the service method is invoked with the cm handle id'
1 * mockNetworkCmProxyDataService.getNcmpServiceCmHandle('some-cm-handle') >> ncmpServiceCmHandle
when: 'the cm handle details api is invoked'
def response = mvc.perform(get(cmHandleDetailsEndpoint)).andReturn().response
then: 'the correct response is returned'
response.status == HttpStatus.OK.value()
- and: 'the response returns the correct state and timestamp'
- response.contentAsString.contains('some-cm-handle')
- response.contentAsString.contains('ADVISED')
- response.contentAsString.contains('2022-12-31T20:30:40.000+0000')
+ and: 'the response contains the public properties'
+ assertContainsPublicProperties(response)
+ and: 'the response contains the cm handle state'
+ assertContainsState(response)
+ and: 'the content does not contain dmi properties'
+ !response.contentAsString.contains("some DMI property")
}
def 'Get Cm Handle public properties by Cm Handle id.' () {
@@ -293,8 +297,23 @@ class NetworkCmProxyControllerSpec extends Specification {
def response = mvc.perform(get(cmHandlePropertiesEndpoint)).andReturn().response
then: 'the correct response is returned'
response.status == HttpStatus.OK.value()
- and: 'the response returns public properties and the correct properties'
- response.contentAsString.equals('{"publicCmHandleProperties":[{"public prop":"some public property"}]}')
+ and: 'the response contains the public properties'
+ assertContainsPublicProperties(response)
+ }
+
+ def 'Get Cm Handle composite state by Cm Handle id.' () {
+ given: 'a cm handle state endpoint'
+ def cmHandlePropertiesEndpoint = "$ncmpBasePathV1/ch/some-cm-handle/state"
+ and: 'some cm handle composite state'
+ def compositeState = compositeStateTestObject()
+ and: 'the service method is invoked with the cm handle id returning the cm handle composite state'
+ 1 * mockNetworkCmProxyDataService.getCmHandleCompositeState('some-cm-handle') >> compositeState
+ when: 'the cm handle state api is invoked'
+ def response = mvc.perform(get(cmHandlePropertiesEndpoint)).andReturn().response
+ then: 'the correct response is returned'
+ response.status == HttpStatus.OK.value()
+ and: 'the response contains the cm handle state'
+ assertContainsState(response)
}
def 'Call execute cm handle searches with unrecognized condition name.'() {
@@ -390,12 +409,65 @@ class NetworkCmProxyControllerSpec extends Specification {
':passthrough-running' | 'passthrough-running'
}
+ def 'Get module definitions based on cmHandleId.' () {
+ when: 'get module definition request is performed'
+ def response = mvc.perform(get("$ncmpBasePathV1/ch/some-cmhandle/modules/definitions"))
+ .andReturn().response
+ then: 'ncmp service method to get module definitions is called'
+ mockNetworkCmProxyDataService.getModuleDefinitionsByCmHandleId('some-cmhandle')
+ >> [new ModuleDefinition('sampleModuleName', '2021-10-03',
+ String.format('module sampleModuleName{ %n sample module content %n }'))]
+ and: 'response contains an array with the module name, revision and content where content contains \\n for newlines'
+ response.getContentAsString() == '[{"moduleName":"sampleModuleName","revision":"2021-10-03","content":"module sampleModuleName{ \\n sample module content \\n }"}]'
+ and: 'response returns an OK http code'
+ response.status == HttpStatus.OK.value()
+ }
+
def dataStores() {
DataStores.builder()
.operationalDataStore(Operational.builder()
- .syncState(SyncState.NONE_REQUESTED)
+ .dataStoreSyncState(DataStoreSyncState.NONE_REQUESTED)
.lastSyncTime(formattedDateAndTime.toString()).build()).build()
}
+ def compositeStateTestObject() {
+ new CompositeState(cmHandleState: CmHandleState.ADVISED,
+ lockReason: CompositeState.LockReason.builder().lockReasonCategory(LockReasonCategory.LOCKED_MISBEHAVING).details("lock misbehaving details").build(),
+ lastUpdateTime: formattedDateAndTime.toString(),
+ dataSyncEnabled: false,
+ dataStores: dataStores())
+ }
+
+ def assertContainsAll(response, assertContent) {
+ assertContent.forEach( string -> { assert(response.contentAsString.contains(string)) })
+ return void
+ }
+
+ def assertContainsState(response) {
+ def expectedContent = [
+ '"state":',
+ '"cmHandleState":"ADVISED"',
+ '"reason":"LOCKED_MISBEHAVING"',
+ '"details":"lock misbehaving details"',
+ '"lastUpdateTime":"2022-12-31T20:30:40.000+0000"',
+ '"dataSyncEnabled":false',
+ '"dataSyncState":',
+ '"operational":',
+ '"state":"NONE_REQUESTED"',
+ '"lastSyncTime":"2022-12-31T20:30:40.000+0000"',
+ '"running":null'
+ ]
+ return assertContainsAll(response, expectedContent)
+ }
+
+ def assertContainsPublicProperties(response) {
+ def expectedContent = [
+ '"publicCmHandleProperties":' ,
+ '"public prop"' ,
+ '"some public property"'
+ ]
+ return assertContainsAll(response, expectedContent)
+ }
+
}
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy
index 1563c75b3..ce908e754 100644
--- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy
+++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy
@@ -29,7 +29,7 @@ import org.onap.cps.ncmp.api.impl.exception.DmiRequestException
import org.onap.cps.ncmp.api.impl.exception.HttpClientRequestException
import org.onap.cps.ncmp.api.impl.exception.ServerNcmpException
import org.onap.cps.ncmp.rest.controller.NcmpRestInputMapper
-import org.onap.cps.ncmp.rest.mapper.RestOutputCmHandleStateMapper
+import org.onap.cps.ncmp.rest.mapper.CmHandleStateMapper
import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor
import org.onap.cps.ncmp.rest.util.DeprecationHelper
import org.onap.cps.spi.exceptions.CpsException
@@ -70,7 +70,7 @@ class NetworkCmProxyRestExceptionHandlerSpec extends Specification {
NcmpRestInputMapper ncmpRestInputMapper = Mappers.getMapper(NcmpRestInputMapper)
@SpringBean
- RestOutputCmHandleStateMapper restOutputCmHandleStateMapper = Mappers.getMapper(RestOutputCmHandleStateMapper)
+ CmHandleStateMapper cmHandleStateMapper = Mappers.getMapper(CmHandleStateMapper)
@SpringBean
CpsNcmpTaskExecutor stubbedCpsTaskExecutor = Stub()
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/RestOutputCmHandleStateMapperTest.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapperTest.groovy
index 695ca5ad6..42fda770b 100644
--- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/RestOutputCmHandleStateMapperTest.groovy
+++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapperTest.groovy
@@ -24,19 +24,19 @@ import org.mapstruct.factory.Mappers
import org.onap.cps.ncmp.api.inventory.CmHandleState
import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder
import org.onap.cps.ncmp.api.inventory.LockReasonCategory
-import org.onap.cps.ncmp.api.inventory.SyncState
-import org.onap.cps.ncmp.rest.model.RestOutputCmHandleState
+import org.onap.cps.ncmp.rest.model.CmHandleCompositeState
+import org.onap.cps.ncmp.api.inventory.DataStoreSyncState
import spock.lang.Specification
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
-class RestOutputCmHandleStateMapperTest extends Specification {
+class CmHandleStateMapperTest extends Specification {
def formattedDateAndTime = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
.format(OffsetDateTime.of(2022, 12, 31, 20, 30, 40, 1, ZoneOffset.UTC))
- def objectUnderTest = Mappers.getMapper(RestOutputCmHandleStateMapper)
+ def objectUnderTest = Mappers.getMapper(CmHandleStateMapper)
def 'Composite State to Rest Output CmHandleState'() {
given: 'a composite state model'
@@ -44,12 +44,12 @@ class RestOutputCmHandleStateMapperTest extends Specification {
.withCmHandleState(CmHandleState.ADVISED)
.withLastUpdatedTime(formattedDateAndTime.toString())
.withLockReason(LockReasonCategory.LOCKED_MISBEHAVING, 'locked other details')
- .withOperationalDataStores(SyncState.SYNCHRONIZED, formattedDateAndTime).build()
+ .withOperationalDataStores(DataStoreSyncState.SYNCHRONIZED, formattedDateAndTime).build()
compositeState.setDataSyncEnabled(false)
when: 'mapper is called'
- def result = objectUnderTest.toRestOutputCmHandleState(compositeState)
+ def result = objectUnderTest.toCmHandleCompositeState(compositeState)
then: 'result is of the correct type'
- assert result.class == RestOutputCmHandleState.class
+ assert result.class == CmHandleCompositeState.class
and: 'mapped result should have correct values'
assert !result.dataSyncEnabled
assert result.lastUpdateTime == formattedDateAndTime
diff --git a/cps-ncmp-rest/src/test/resources/application.yml b/cps-ncmp-rest/src/test/resources/application.yml
index 0241696c5..9df1e580f 100644
--- a/cps-ncmp-rest/src/test/resources/application.yml
+++ b/cps-ncmp-rest/src/test/resources/application.yml
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (C) 2021 Nordix Foundation
+# Copyright (C) 2021-2022 Nordix Foundation
# Modifications Copyright (C) 2021 Bell Canada.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,6 +23,7 @@ rest:
ncmp-inventory-base-path: /ncmpInventory
notification:
+ enabled: true
async:
executor:
time-out-value-in-ms: 2000 \ No newline at end of file