* @param interfaceDefinitionToscaMap the TOSCA interface definition structure
* @return an interface definition representation
*/
- public InterfaceDefinition create(final Map<String, Object> interfaceDefinitionToscaMap) {
+ public InterfaceDefinition create(final Map<String, Object> interfaceDefinitionToscaMap, final String model) {
final InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setModel(model);
if (interfaceDefinitionToscaMap.containsKey(TYPE.getElementName())) {
final Object typeObj = interfaceDefinitionToscaMap.get(TYPE.getElementName());
if (!(typeObj instanceof String)) {
operationMap = handleLegacyOperations(interfaceDefinitionToscaMap);
}
if (!operationMap.isEmpty()) {
- validateOperations(interfaceDefinition.getType(), operationMap);
+ validateOperations(interfaceDefinition.getType(), operationMap, model);
interfaceDefinition.setOperations(operationMap);
}
return interfaceDefinition;
}
- private void validateOperations(final String interfaceType, final Map<String, OperationDataDefinition> operationMap) {
+ private void validateOperations(final String interfaceType, final Map<String, OperationDataDefinition> operationMap, final String model) {
if (MapUtils.isEmpty(operationMap)) {
return;
}
Either<Map<String, InterfaceDefinition>, ResponseFormat> interfaceDefinitionMapEither = interfaceOperationBusinessLogic
- .getAllInterfaceLifecycleTypes();
+ .getAllInterfaceLifecycleTypes(model);
if (interfaceDefinitionMapEither.isRight() || MapUtils.isEmpty(interfaceDefinitionMapEither.left().value())) {
throw new ByActionStatusComponentException(ActionStatus.INTERFACE_UNKNOWN, interfaceType);
}
}
org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
lockComponentResult(lock, storedComponent, errorContext);
- Either<Map<String, InterfaceDefinition>, ResponseFormat> interfaceLifecycleTypes = getAllInterfaceLifecycleTypes();
+ Either<Map<String, InterfaceDefinition>, ResponseFormat> interfaceLifecycleTypes = getAllInterfaceLifecycleTypes(storedComponent.getModel());
if (interfaceLifecycleTypes.isRight()) {
return Either.right(interfaceLifecycleTypes.right().value());
}
}
}
- public Either<Map<String, InterfaceDefinition>, ResponseFormat> getAllInterfaceLifecycleTypes() {
+ public Either<Map<String, InterfaceDefinition>, ResponseFormat> getAllInterfaceLifecycleTypes(final String model) {
Either<Map<String, InterfaceDefinition>, StorageOperationStatus> interfaceLifecycleTypes = interfaceLifecycleTypeOperation
- .getAllInterfaceLifecycleTypes();
+ .getAllInterfaceLifecycleTypes(model);
if (interfaceLifecycleTypes.isRight()) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_LIFECYCLE_TYPES_NOT_FOUND));
}
import static org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementOperation.createDataType;
import static org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementOperation.createDataTypeDefinitionWithName;
-import fj.data.Either;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+
import javax.servlet.ServletContext;
+
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.context.WebApplicationContext;
import org.yaml.snakeyaml.Yaml;
+import fj.data.Either;
+
@Component("resourceImportManager")
public class ResourceImportManager {
Map<String, Object> jsonInterfaces = toscaInterfaces.left().value();
Map<String, InterfaceDefinition> moduleInterfaces = new HashMap<>();
for (final Entry<String, Object> interfaceNameValue : jsonInterfaces.entrySet()) {
- final Either<InterfaceDefinition, ResultStatusEnum> eitherInterface = createModuleInterface(interfaceNameValue.getValue());
+ final Either<InterfaceDefinition, ResultStatusEnum> eitherInterface = createModuleInterface(interfaceNameValue.getValue(), resource.getModel());
if (eitherInterface.isRight()) {
log.info("error when creating interface:{}, for resource:{}", interfaceNameValue.getKey(), resource.getName());
} else {
}
}
- private Either<InterfaceDefinition, ResultStatusEnum> createModuleInterface(final Object interfaceJson) {
+ private Either<InterfaceDefinition, ResultStatusEnum> createModuleInterface(final Object interfaceJson, final String model) {
try {
if (interfaceJson instanceof String) {
final InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
}
if (interfaceJson instanceof Map) {
final Map<String, Object> interfaceJsonMap = (Map<String, Object>) interfaceJson;
- final InterfaceDefinition interfaceDefinition = interfaceDefinitionHandler.create(interfaceJsonMap);
+ final InterfaceDefinition interfaceDefinition = interfaceDefinitionHandler.create(interfaceJsonMap, model);
return Either.left(interfaceDefinition);
}
return Either.right(ResultStatusEnum.GENERAL_ERROR);
*/
package org.openecomp.sdc.be.servlets;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.servers.Server;
-import io.swagger.v3.oas.annotations.servers.Servers;
-import io.swagger.v3.oas.annotations.tags.Tag;
-import io.swagger.v3.oas.annotations.tags.Tags;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
+
import javax.inject.Inject;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+
import org.apache.commons.collections4.ListUtils;
-import org.glassfish.jersey.media.multipart.FormDataParam;
import org.openecomp.sdc.be.components.impl.CapabilitiesBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.stereotype.Controller;
+import com.jcabi.aspects.Loggable;
+
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.servers.Server;
+import io.swagger.v3.oas.annotations.servers.Servers;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import io.swagger.v3.oas.annotations.tags.Tags;
+
@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
@Path("/v1/catalog")
@Tags({@Tag(name = "SDCE-2 APIs")})
@ApiResponse(responseCode = "404", description = "Interface lifecycle types not found")})
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response getInterfaceLifecycleTypes(@Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "model") @QueryParam("model") String modelName) {
Wrapper<Response> responseWrapper = new Wrapper<>();
Wrapper<User> userWrapper = new Wrapper<>();
try {
String url = request.getMethod() + " " + request.getRequestURI();
log.info("Start handle request of {} | modifier id is {}", url, userId);
Either<Map<String, InterfaceDefinition>, ResponseFormat> allInterfaceLifecycleTypes = interfaceOperationBusinessLogic
- .getAllInterfaceLifecycleTypes();
+ .getAllInterfaceLifecycleTypes(modelName);
if (allInterfaceLifecycleTypes.isRight()) {
log.info("Failed to get all interface lifecycle types. Reason - {}", allInterfaceLifecycleTypes.right().value());
Response errorResponse = buildErrorResponse(allInterfaceLifecycleTypes.right().value());
log.debug("start convert node type for {}", component.getUniqueId());
ToscaNodeType toscaNodeType = createNodeType(component);
Either<Map<String, InterfaceDefinition>, StorageOperationStatus> lifecycleTypeEither = interfaceLifecycleOperation
- .getAllInterfaceLifecycleTypes();
+ .getAllInterfaceLifecycleTypes(component.getModel());
if (lifecycleTypeEither.isRight()) {
log.debug("Failed to fetch all interface types :", lifecycleTypeEither.right().value());
return Either.right(ToscaError.GENERAL_ERROR);
}
Either<Map<String, InterfaceDefinition>, StorageOperationStatus> lifecycleTypeEither =
- interfaceLifecycleOperation.getAllInterfaceLifecycleTypes();
+ interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(serviceComponent.getModel());
if (lifecycleTypeEither.isRight()) {
log.debug("Failed to retrieve global interface types :", lifecycleTypeEither.right().value());
return Either.right(ToscaError.GENERAL_ERROR);
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
-import fj.data.Either;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.openecomp.sdc.exception.PolicyException;
import org.openecomp.sdc.exception.ResponseFormat;
+import fj.data.Either;
+
public class ResourceImportManagerTest {
static ResourceImportManager importManager;
operations.put("configure", new OperationDataDefinition());
interfaceDefinition.setOperations(operations );
interfaceTypes.put("tosca.interfaces.node.lifecycle.standard", interfaceDefinition);
- when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(interfaceTypes));
+ when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(interfaceTypes));
final ImmutablePair<Resource, ActionStatus> createResource = importManager
.importNormativeResource(jsonContent, resourceMD, user, true, true);
operations.put("configure", new OperationDataDefinition());
interfaceDefinition.setOperations(operations );
interfaceTypes.put("tosca.interfaces.node.lifecycle.standard", interfaceDefinition);
- when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(interfaceTypes));
+ when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(interfaceTypes));
ImmutablePair<Resource, ActionStatus> createResource = importManager.importNormativeResource(jsonContent, resourceMD, user, true, true);
assertNull(createResource.left.getInterfaces());
operations.put("configure", new OperationDataDefinition());
interfaceDefinition.setOperations(operations );
interfaceTypes.put("tosca.interfaces.node.lifecycle.standard", interfaceDefinition);
- when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(interfaceTypes));
+ when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(interfaceTypes));
ImmutablePair<Resource, ActionStatus> createResource = importManager.importNormativeResource(jsonContent, resourceMD, user, true, true);
assertNull(createResource.left.getInterfaces());
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.when;
-import fj.data.Either;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
+
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.yaml.snakeyaml.Yaml;
+import fj.data.Either;
+
@ExtendWith(MockitoExtension.class)
class InterfaceDefinitionHandlerTest {
operations.put(DELETE_OPERATION, new OperationDataDefinition());
interfaceLifecyleStandard.setOperations(operations);
interfaceTypes.put(INTERFACE_TYPE, interfaceLifecyleStandard);
- when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(interfaceTypes));
+ when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(StringUtils.EMPTY)).thenReturn(Either.left(interfaceTypes));
}
@Test
void testCreateWithLegacyOperationDeclarationSuccess() throws FileNotFoundException {
final Map<String, Object> load = loadYaml(Paths.get("interfaceDefinition-legacy.yaml"));
- final InterfaceDefinition actualInterfaceDefinition = interfaceDefinitionHandler.create(load);
+ final InterfaceDefinition actualInterfaceDefinition = interfaceDefinitionHandler.create(load, StringUtils.EMPTY);
assertInterfaceDefinition(actualInterfaceDefinition);
}
@Test
void testCreateWithOperationSuccess() throws FileNotFoundException {
final Map<String, Object> load = loadYaml(Paths.get("interfaceDefinition-tosca1.3.yaml"));
- final InterfaceDefinition actualInterfaceDefinition = interfaceDefinitionHandler.create(load);
+ final InterfaceDefinition actualInterfaceDefinition = interfaceDefinitionHandler.create(load, StringUtils.EMPTY);
assertInterfaceDefinition(actualInterfaceDefinition);
}
package org.openecomp.sdc.be.components.impl;
-import fj.data.Either;
+import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openecomp.sdc.exception.ResponseFormat;
import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.fail;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyBoolean;
-import static org.mockito.ArgumentMatchers.anyMap;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.when;
+import fj.data.Either;
@RunWith(MockitoJUnitRunner.class)
public class InterfaceOperationBusinessLogicTest {
@Test
public void createInterfaceOperationTestOnExistingInterface() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(Collections.emptyMap()));
when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
@Test
public void createInterfaceOperationTestOnExistingInterfaceInputsFromCapProp() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(Collections.emptyMap()));
when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
@Test
public void createInterfaceOperationWithoutInterfaceTest() {
resource.getInterfaces().clear();
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(Collections.emptyMap()));
when(interfaceOperation.addInterfaces(any(), any())).thenReturn(Either.left(
Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
@Test
public void createInterfaceOperationWithoutInterfaceTestFail() {
resource.getInterfaces().clear();
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(Collections.emptyMap()));
when(interfaceOperation.addInterfaces(any(), any()))
.thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
@Test
public void shouldFailWhenCreateInterfaceOperationFailedTest() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(Collections.emptyMap()));
when(interfaceOperation.updateInterfaces(any(), any()))
.thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
@Test
public void updateInterfaceOperationTestWithArtifactSuccess() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(Collections.emptyMap()));
when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
.thenReturn(Either.left(new ArtifactDefinition()));
@Test
public void updateInterfaceOperationTestWithArtifactFailure() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(Collections.emptyMap()));
when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
@Test
public void updateInterfaceOperationTestWithoutArtifact() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(Collections.emptyMap()));
when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
@Test
public void updateInterfaceOperationTestDoesntExist() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(Collections.emptyMap()));
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId,
@Test
public void createInterfaceOperationTestFailOnException() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(Collections.emptyMap()));
when(interfaceOperation.updateInterfaces(any(), any())).thenThrow(new RuntimeException());
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
@Test
public void createInterfaceOperationTestFailOnFetchinGlobalTypes() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
@Test
public void createInterfaceOperationTestFailOnValidation() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(Collections.emptyMap()));
when(interfaceOperationValidation
.validateInterfaceOperations(any(), any(), any(), anyMap(), anyBoolean()))
@Test
public void testGetAllInterfaceLifecycleTypes_TypesNotFound() {
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
Either<Map<String, InterfaceDefinition>, ResponseFormat> response =
- interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes();
+ interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(any());
Assert.assertTrue(response.isRight());
}
interfaceDefinition.setType(interfaceId);
Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>();
interfaceDefinitionMap.put(interfaceDefinition.getUniqueId(), interfaceDefinition);
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(interfaceDefinitionMap));
Either<Map<String, InterfaceDefinition>, ResponseFormat> response =
- interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes();
+ interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(StringUtils.EMPTY);
Assert.assertEquals(1, response.left().value().size());
}
when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class),
any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(Collections.emptyMap()));
// default test when component is Resource
((Resource) component).setInterfaces(new HashMap<>());
when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(Collections.emptyMap()));
// default test when convertInterfaceNodeType is right
result = testSubject.exportComponentInterface(component, false);
component.setName(RESOURCE_NAME);
component.setToscaResourceName(RESOURCE_NAME);
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(Collections.emptyMap()));
when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
// when convertRequirements is called, make it return the same value as 3rd (index=2) argument.
Either<ToscaTemplate, ToscaError> result;
when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.ALREADY_EXIST));
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(Collections.emptyMap()));
// default test
result = Deencapsulation
component.setInputs(inputs);
when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(Collections.emptyMap()));
when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class),
when(capabilityRequirementConverter
.convertComponentInstanceCapabilities(any(ComponentInstance.class), any(Map.class), any(ToscaNodeTemplate.class)))
.thenReturn(Either.left(new ToscaNodeTemplate()));
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(Collections.emptyMap()));
when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), any(ToscaNodeType.class)))
.thenReturn(Either.left(new ToscaNodeType()));
when(capabilityRequirementConverter
.convertComponentInstanceCapabilities(any(ComponentInstance.class), any(Map.class), any(ToscaNodeTemplate.class)))
.thenReturn(Either.left(new ToscaNodeTemplate()));
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(Collections.emptyMap()));
when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), any(ToscaNodeType.class)))
.thenReturn(Either.left(new ToscaNodeType()));
when(capabilityRequirementConverter
.convertComponentInstanceCapabilities(any(ComponentInstance.class), any(Map.class), any(ToscaNodeTemplate.class)))
.thenReturn(Either.right(ToscaError.GENERAL_ERROR));
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(Collections.emptyMap()));
when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class),
any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
componentCache.put("uid", component);
when(capabilityRequirementConverter.getOriginComponent(any(Map.class), any(ComponentInstance.class))).thenReturn(Either.right(false));
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(Collections.emptyMap()));
when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class),
any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
doReturn(Either.left(component)).when(toscaOperationFacade).getToscaFullElement("id");
when(capabilityRequirementConverter.getOriginComponent(any(Map.class), any(ComponentInstance.class))).thenReturn(Either.left(component));
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap()));
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(Collections.emptyMap()));
when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class),
any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
when(toscaOperationFacade.getToscaElement(any(String.class),
any(ComponentParametersView.class)))
.thenReturn(Either.left(new Resource()));
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
result = Deencapsulation.invoke(testSubject, "createProxyInterfaceTypes", container);
Assert.assertTrue(result.isRight());
componentInstances.add(instance);
container.setComponentInstances(componentInstances);
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(Collections.emptyMap()));
Component proxyResource = new Resource();
componentInstances.add(instance);
containerService.setComponentInstances(componentInstances);
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
.thenReturn(Either.left(Collections.emptyMap()));
when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Service.class),
*/
package org.openecomp.sdc.be.model.operations.api;
-import fj.data.Either;
import java.util.Map;
+
import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Operation;
+import fj.data.Either;
+
public interface IInterfaceLifecycleOperation {
public Either<InterfaceDefinition, StorageOperationStatus> createInterfaceOnResource(InterfaceDefinition interf, String resourceId,
public String getShortInterfaceName(InterfaceDataDefinition interfaceDefinition);
- Either<Map<String, InterfaceDefinition>, StorageOperationStatus> getAllInterfaceLifecycleTypes();
+ Either<Map<String, InterfaceDefinition>, StorageOperationStatus> getAllInterfaceLifecycleTypes(final String model);
+
}
}
@Override
- public Either<Map<String, InterfaceDefinition>, StorageOperationStatus> getAllInterfaceLifecycleTypes() {
+ public Either<Map<String, InterfaceDefinition>, StorageOperationStatus> getAllInterfaceLifecycleTypes(final String model) {
Either<List<InterfaceData>, JanusGraphOperationStatus> allInterfaceLifecycleTypes = janusGraphGenericDao
- .getByCriteria(NodeTypeEnum.Interface, Collections.emptyMap(), InterfaceData.class);
+ .getByCriteriaForModel(NodeTypeEnum.Interface, Collections.emptyMap(), model, InterfaceData.class);
if (allInterfaceLifecycleTypes.isRight()) {
return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(allInterfaceLifecycleTypes.right().value()));
}
import java.util.List;
import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.Assert;
import org.junit.Before;
@Test
public void testGetAllInterfaceLifecycleTypes_TypesNotFound() {
- when(janusGraphGenericDao.getByCriteria(NodeTypeEnum.Interface, Collections.emptyMap(),
+ when(janusGraphGenericDao.getByCriteriaForModel(NodeTypeEnum.Interface, Collections.emptyMap(), StringUtils.EMPTY,
InterfaceData.class)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
- Either<Map<String, InterfaceDefinition>, StorageOperationStatus> types = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes();
+ Either<Map<String, InterfaceDefinition>, StorageOperationStatus> types = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(StringUtils.EMPTY);
Assert.assertEquals(types.isRight(), Boolean.TRUE);
}
interfaceDataList.add(interfaceData);
Either<List<InterfaceData>, JanusGraphOperationStatus> allInterfaceTypes = Either.left(interfaceDataList);
when(janusGraphGenericDao
- .getByCriteria(NodeTypeEnum.Interface, Collections.emptyMap(), InterfaceData.class)).thenReturn(allInterfaceTypes);
+ .getByCriteriaForModel(NodeTypeEnum.Interface, Collections.emptyMap(), StringUtils.EMPTY, InterfaceData.class)).thenReturn(allInterfaceTypes);
List<ImmutablePair<OperationData, GraphEdge>> list = new ArrayList<>();
Either<List<ImmutablePair<OperationData, GraphEdge>>, JanusGraphOperationStatus> childrenNodes = Either.left(list);
when(janusGraphGenericDao.getChildrenNodes(interfaceData.getUniqueIdKey(), interfaceData.getUniqueId(), GraphEdgeLabels.INTERFACE_OPERATION, NodeTypeEnum.InterfaceOperation, OperationData.class)).thenReturn(childrenNodes);
when(janusGraphGenericDao.getParentNode(any(), any(), any(), any(), any()))
.thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
- Either<Map<String, InterfaceDefinition>, StorageOperationStatus> types = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes();
+ Either<Map<String, InterfaceDefinition>, StorageOperationStatus> types = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(StringUtils.EMPTY);
Assert.assertEquals(types.left().value().size(),1);
}
when(janusGraphGenericDao.getParentNode(any(), any(), any(), any(), any()))
.thenReturn(Either.left(modelNode));
when(janusGraphGenericDao
- .getByCriteria(NodeTypeEnum.Interface, Collections.emptyMap(), InterfaceData.class)).thenReturn(Either.left(interfaceTypes));
+ .getByCriteriaForModel(NodeTypeEnum.Interface, Collections.emptyMap(), MODEL_NAME, InterfaceData.class)).thenReturn(Either.left(interfaceTypes));
when(janusGraphGenericDao.getChildrenNodes(interfaceData.getUniqueIdKey(), interfaceData.getUniqueId(), GraphEdgeLabels.INTERFACE_OPERATION, NodeTypeEnum.InterfaceOperation, OperationData.class)).thenReturn(Either.left(Collections.emptyList()));
- Assert.assertEquals(1, interfaceLifecycleOperation.getAllInterfaceLifecycleTypes().left().value().size());
+ Assert.assertEquals(1, interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(MODEL_NAME).left().value().size());
}
}
}
private loadInterfaceTypeMap(): void {
- this.componentService.getInterfaceTypes(null).subscribe(response => {
+ this.componentService.getInterfaceTypes(this.component).subscribe(response => {
for (const interfaceType in response) {
let operationList = response[interfaceType];
//ignore interfaceTypes that doesn't contain operations
}
getInterfaceTypes(component:Component):Observable<{[id:string]: Array<string>}> {
- return this.http.get<any>(this.baseUrl + 'interfaceLifecycleTypes')
+ return this.http.get<any>(this.baseUrl + 'interfaceLifecycleTypes' + ((component && component.model) ? '?model=' + component.model : ''))
.map((res: any) => {
const interfaceMap = {};
if (!res) {