* ================================================================================
* Modifications Copyright (C) 2018 IBM.
* ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
+ * ================================================================================
* 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
public class ExecuteNodeActionImpl implements ExecuteNodeAction {
- private static final EELFLogger logger = EELFManager.getInstance().getLogger(ExecuteNodeActionImpl.class);
private static final String RESOURCE_TYPE_PARAM = "resourceType";
private static final String RESOURCE_KEY_PARAM = "resourceKey";
private static final String PREFIX_PARAM = "prefix";
private static final String ERROR_RETRIEVING_VNFC_HIERARCHY_PARAM = "Error Retrieving VNFC hierarchy";
private static final String RELATED_TO_PROPERTY_LEN_PARAM = "related-to-property_length";
public static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message";
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(ExecuteNodeActionImpl.class);
private static Map<String, String> vnfHierarchyMap = new ConcurrentHashMap<>();
private static Map<String, Set<String>> vnfcHierarchyMap = new HashMap<>();
logger.info("DG waits for " + Long.parseLong(waitTime) + " milliseconds completed");
} catch (InterruptedException e) {
logger.error("Error In ExecuteNodeActionImpl for waitMethod() due to InterruptedException: reason = "
- + e.getMessage());
+ + e.getMessage(), e);
+ Thread.currentThread().interrupt();
}
}
String resourceKey = params.get(RESOURCE_KEY_PARAM);
if (logger.isDebugEnabled()) {
- logger.debug("inside getResorce");
+ logger.debug("inside getResource");
logger.debug("Retrieving " + resourceType + " details from A&AI for Key : " + resourceKey);
}
// and tenant-id
String key = vnfCtx.getAttribute(vmKey + RELATIONSHIP_DATA_STR + j + "].relationship-key");
String value = vnfCtx.getAttribute(vmKey + RELATIONSHIP_DATA_STR + j + "].relationship-value");
+
vnfHierarchyMap.put(VNFF_VM_STR + vmCount + "]." + key, value);
if ("vserver.vserver-id".equals(key)) {
vserverID = value;
paramsVm.put(RESOURCE_TYPE_PARAM, "vserver");
paramsVm.put(PREFIX_PARAM, "vmRetrived");
paramsVm.put(RESOURCE_KEY_PARAM, vmRetrivalKey);
- SvcLogicContext vmCtx = new SvcLogicContext();
+ SvcLogicContext vmCtx = getSvcLogicContext();
logger.debug("Retrieving VM details from A&AI");
getResource(paramsVm, vmCtx);
paramsVnf.put(RESOURCE_KEY_PARAM, retrivalVnfKey);
logger.debug("Retrieving VNF details from A&AI");
// Retrive all the relations of VNF
- SvcLogicContext vnfCtx = new SvcLogicContext();
+ SvcLogicContext vnfCtx = getSvcLogicContext();
getResource(paramsVnf, vnfCtx);
if (vnfCtx.getAttribute(GET_RESOURCE_RESULT).equals(SUCCESS_PARAM)) {
trySetHeatStackIDAttribute(ctx, vnfCtx);
vnfcCounter++;
}
}
+
+ protected SvcLogicContext getSvcLogicContext() {
+ return new SvcLogicContext();
+ }
}
* ================================================================================
* Modifications Copyright (C) 2018 Nokia
* ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
+ * ================================================================================
* 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
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
+import org.powermock.reflect.Whitebox;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.configuration.EELFLogger.Level;
@RunWith(MockitoJUnitRunner.class)
public class ExecuteNodeActionImplTest {
private static final SvcLogicContext SVC_LOGIC_CONTEXT = new SvcLogicContext();
private static final SvcLogicResource.QueryStatus SUCCESS_STATUS = SvcLogicResource.QueryStatus.SUCCESS;
private static final QueryStatus FAILED_STATUS = SvcLogicResource.QueryStatus.FAILURE;
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(ExecuteNodeActionImpl.class);
+ private static EELFLogger.Level originalLoggerLevel;
+
@Mock
private AAIServiceFactory aaiServiceFactory;
params.put("attributeName", attributeName);
params.put("attributeValue", attributeValue);
params.put("waitTime", "1");
+ originalLoggerLevel = logger.isDebugEnabled() ? Level.DEBUG : Level.INFO;
+ logger.setLevel(Level.DEBUG);
}
@Test
@Test
public void testGetVnfHierarchySuccess() throws Exception {
+ ExecuteNodeActionImpl executeNodeActionSpy = Mockito.spy(executeNodeAction);
given(aaiService.query(any(), Mockito.anyBoolean(),
any(), any(), any(), any(),
any(SvcLogicContext.class))).willReturn(SUCCESS_STATUS);
-
- executeNodeAction.getVnfHierarchy(params, SVC_LOGIC_CONTEXT);
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute(("vnfRetrived.heat-stack-id"), "TEST");
+ Mockito.when(executeNodeActionSpy.getSvcLogicContext()).thenReturn(ctx);
+ executeNodeActionSpy.getVnfHierarchy(params, SVC_LOGIC_CONTEXT);
assertEquals("0", SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFCCount"));
assertEquals("SUCCESS", SVC_LOGIC_CONTEXT.getAttribute("getVnfHierarchy_result"));
given(aaiService.query(any(), Mockito.anyBoolean(),
any(), any(), any(), any(),
any(SvcLogicContext.class))).willReturn(FAILED_STATUS);
-
executeNodeAction.getVnfHierarchy(params, SVC_LOGIC_CONTEXT);
assertEquals("0", SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFCCount"));
assertTrue(vServersList.contains(SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFC[0].VM[0].URL")));
assertTrue(vServersList.contains(SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFC[0].VM[1].URL")));
}
+
+ @Test
+ public void testGetVserverRelations() throws Exception {
+ ExecuteNodeActionImpl executeNodeActionSpy = Mockito.spy(executeNodeAction);
+ given(aaiService.query(any(), Mockito.anyBoolean(),
+ any(), any(), any(), any(),
+ any(SvcLogicContext.class))).willReturn(SUCCESS_STATUS);
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute(("vnfRetrived.related-to"), "vserver");
+ ctx.setAttribute("vnfRetrived.relationship-data_length", "1");
+ ctx.setAttribute("vnfRetrived.related-to-property_length", "1");
+ ctx.setAttribute("vnfRetrived.relationship-data[0].relationship-key", "KEY");
+ ctx.setAttribute("vnfRetrived.relationship-data[0].relationship-value", "VALUE");
+ ctx.setAttribute("vnfRetrived.related-to-property[0].property-key", "KEY");
+ ctx.setAttribute("vnfRetrived.related-to-property[0].property-value", "VALUE");
+ ctx.setAttribute("vmRetrived.vserver-selflink", "URL");
+ ctx.setAttribute("vmRetrived.related-to", "vnfc");
+ ctx.setAttribute("vmRetrived.relationship-data_length", "1");
+ ctx.setAttribute("vmRetrived.relationship-data[0].relationship-key", "vnfc.vnfc-name");
+ ctx.setAttribute("vmRetrived.relationship-data[0].relationship-value", "VALUE");
+ Mockito.when(executeNodeActionSpy.getSvcLogicContext()).thenReturn(ctx);
+ executeNodeActionSpy.getVnfHierarchy(params, SVC_LOGIC_CONTEXT);
+
+ assertEquals("1", SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFCCount"));
+ assertEquals("SUCCESS", SVC_LOGIC_CONTEXT.getAttribute("getVnfHierarchy_result"));
+ }
+
+ @AfterClass
+ public static void restoreLogger() {
+ logger.setLevel(originalLoggerLevel);
+ }
+
}