From 574417bd1d70e30e7074f7f3375ea443b44740ab Mon Sep 17 00:00:00 2001 From: Skip Wonnell Date: Mon, 28 Aug 2017 22:02:54 -0500 Subject: [PATCH] Clean up directed graph java code Issue-ID: APPC-90 Change-Id: I3ea4912523eed1fed85aa2e5909ec897bb13b72b Signed-off-by: Skip Wonnell --- appc-directed-graph/appc-dgraph/pom.xml | 55 ++-- .../appc/dg/TestPublishConfiguration.java | 87 +---- .../appc/dg/mock/instance/MockAaiResource.java | 349 +++++++++------------ .../mock/instance/MockConfigureNodeExecutor.java | 77 +++-- .../dg/mock/instance/MockSvcLogicJavaPlugin.java | 182 +++++------ .../PublishConfig_Failure.properties | 1 + .../PublishConfig_Success.properties | 1 + .../features/src/main/resources/features.xml | 1 + appc-directed-graph/dg-loader/pom.xml | 61 ++-- appc-directed-graph/dg-loader/provider/pom.xml | 31 +- .../sdnc/dg/loader/DGLoaderActivator.java | 32 +- .../openecomp/sdnc/dg/loader/DGXMLActivate.java | 173 +++++----- .../openecomp/sdnc/dg/loader/DGXMLGenerator.java | 180 +++++------ .../org/openecomp/sdnc/dg/loader/DGXMLLoad.java | 130 ++++---- .../sdnc/dg/loader/DGXMLLoadNActivate.java | 256 +++++++-------- .../src/main/resources/scripts/dg_load_activate.sh | 1 + appc-directed-graph/pom.xml | 28 +- 17 files changed, 740 insertions(+), 905 deletions(-) diff --git a/appc-directed-graph/appc-dgraph/pom.xml b/appc-directed-graph/appc-dgraph/pom.xml index d421dd3cb..508bcfcee 100644 --- a/appc-directed-graph/appc-dgraph/pom.xml +++ b/appc-directed-graph/appc-dgraph/pom.xml @@ -1,6 +1,31 @@ - + + + org.openecomp.appc appc-directed-graph @@ -13,7 +38,7 @@ appc-dgraph 1.1.0-SNAPSHOT - APPC DG + APPC Directed Graph APPC DG Module @@ -23,31 +48,9 @@ 1.1.0 1.1.0 1.1.0 + ${project.parent.parent.basedir} - - - - - org.openecomp.sdnctl - appc-dg-provider - ${project.version} - - - - - org.openecomp.sdnc.core - sli-provider - - - - org.openecomp.sdnc.core - dblib-provider - ${sdnctl.dblib.version} - - - - default diff --git a/appc-directed-graph/appc-dgraph/provider/src/test/java/org/openecomp/appc/dg/TestPublishConfiguration.java b/appc-directed-graph/appc-dgraph/provider/src/test/java/org/openecomp/appc/dg/TestPublishConfiguration.java index bae40347b..357896e30 100644 --- a/appc-directed-graph/appc-dgraph/provider/src/test/java/org/openecomp/appc/dg/TestPublishConfiguration.java +++ b/appc-directed-graph/appc-dgraph/provider/src/test/java/org/openecomp/appc/dg/TestPublishConfiguration.java @@ -39,94 +39,13 @@ import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; -/* need to move to OPENSOURCE -import org.apache.sling.testing.mock.osgi.MockOsgi; -import com.att.sdnctl.dgtestlibrary.AbstractDGTestCase; -import com.att.sdnctl.dgtestlibrary.DGTestCase; -import com.att.sdnctl.dgtestlibrary.GraphKey; -*/ import org.openecomp.sdnc.sli.SvcLogicContext; import org.openecomp.sdnc.sli.provider.ExecuteNodeExecutor; import org.openecomp.sdnc.sli.provider.SvcLogicAdaptorFactory; -public class TestPublishConfiguration /* extends AbstractDGTestCase */ { - //private final static Logger logger = LoggerFactory.getLogger(TestGetParams.class); - private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestPublishConfiguration.class); - public static String PublishConfigurationXML = "src/main/resources/xml/APPC_PublishConfiguration.xml"; - - -/* - - @Test - public void TestPublishConfigurationSuccess() { - try { - - String propertyfileName = "APPC/PublishConfiguration/PublishConfig_Success.properties"; - Map serviceReferences = new HashMap(); - - - serviceReferences.put("org.openecomp.sdnc.config.generator.convert.ConvertNode", new org.openecomp.sdnc.config.generator.convert.ConvertNode()); - - - - serviceReferences.put("org.openecomp.sdnc.config.generator.writer.FileWriterNode", new org.openecomp.sdnc.config.generator.writer.FileWriterNode()); - // Register Call graphs - String injectGraphXmls[] = new String[] { PublishConfigurationXML }; - - - GraphKey graphKey = new GraphKey("APPC", null, "PublishConfiguration", null); - DGTestCase tc = new DGTestCase(graphKey); - tc.setInjectGraphXmls(injectGraphXmls); - tc.setServiceReferences(serviceReferences); - tc.setPropertyfileName(propertyfileName); - - SvcLogicContext ctx = new SvcLogicContext(); - processTestCase(tc, ctx); - - System.out.println("JSON " + ctx.getAttribute("tmp.jsonConversion.jsonContent")); - - - } catch (Exception e) { - e.printStackTrace(); - } - - } - - - - - @Test - public void TestPublishConfigurationFailure() { - try { - - String propertyfileName = "APPC/PublishConfiguration/PublishConfig_Failure.properties"; - Map serviceReferences = new HashMap(); - - - // Register Call graphs - String injectGraphXmls[] = new String[] { PublishConfigurationXML }; - - - GraphKey graphKey = new GraphKey("APPC", null, "PublishConfiguration", null); - DGTestCase tc = new DGTestCase(graphKey); - tc.setInjectGraphXmls(injectGraphXmls); - tc.setServiceReferences(serviceReferences); - tc.setPropertyfileName(propertyfileName); - - SvcLogicContext ctx = new SvcLogicContext(); - processTestCase(tc, ctx); - - - } catch (Exception e) { - e.printStackTrace(); - } - - } - - - -*/ - +public class TestPublishConfiguration { + private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestPublishConfiguration.class); + public static String PublishConfigurationXML = "src/main/resources/xml/APPC_PublishConfiguration.xml"; } diff --git a/appc-directed-graph/appc-dgraph/provider/src/test/java/org/openecomp/appc/dg/mock/instance/MockAaiResource.java b/appc-directed-graph/appc-dgraph/provider/src/test/java/org/openecomp/appc/dg/mock/instance/MockAaiResource.java index 5e55f2f31..9a271fae4 100644 --- a/appc-directed-graph/appc-dgraph/provider/src/test/java/org/openecomp/appc/dg/mock/instance/MockAaiResource.java +++ b/appc-directed-graph/appc-dgraph/provider/src/test/java/org/openecomp/appc/dg/mock/instance/MockAaiResource.java @@ -35,211 +35,150 @@ import static org.junit.Assert.*; public class MockAaiResource implements SvcLogicResource { - private final static Logger logger = LoggerFactory.getLogger(MockAaiResource.class); - - @Override - public QueryStatus isAvailable(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException { - - return QueryStatus.SUCCESS; - - } - - @Override - public QueryStatus exists(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException { - - return QueryStatus.SUCCESS; - } - - - - public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix, String orderBy, SvcLogicContext ctx) throws SvcLogicException { - - if (ctx.getAttribute("j").equals("0") && "tmp.aai-data-vm".equals(prefix)) { - logger.info("Mock VM Get query1 called " + ctx.getAttribute("j") ); - - assertEquals(resource, "vserver"); - assertEquals(key, "'vserver-name = $request-parameters.vm[$j].vm-name'"); - - ctx.setAttribute("tmp.aai-data-vm.vserver-id", "vserverid1"); - - ctx.setAttribute("tmp.aai-data-vm.tenant-id", "tenantid1"); - ctx.setAttribute("tmp.aai-data-vm.cloud-owner", "att-aic"); - ctx.setAttribute("tmp.aai-data-vm.cloud-region-id", "cloudregionid1"); - } - else if (ctx.getAttribute("j").equals("1") && "tmp.aai-data-vm".equals(prefix)) { - logger.info("Mock VM Get query1 called " + ctx.getAttribute("j") ); - - assertEquals(resource, "vserver"); - assertEquals(key, "'vserver-name = $request-parameters.vm[$j].vm-name'"); - - - ctx.setAttribute("tmp.aai-data-vm.vserver-id", "vserverid2"); - - ctx.setAttribute("tmp.aai-data-vm.tenant-id", "tenantid2"); - ctx.setAttribute("tmp.aai-data-vm.cloud-owner", "att-aic"); - ctx.setAttribute("tmp.aai-data-vm.cloud-region-id", "cloudregionid2"); - } - else if ("tmp.aai-data-vnfc".equals(prefix)) { - logger.info("Mock VNFC Get query1 called " ); - - assertEquals(resource, "vnfc"); - assertEquals(key, "'vnfc-name = $request-parameters.vm[$j].vnfc[$k].vnfc-name'"); - - return QueryStatus.NOT_FOUND; - } - return QueryStatus.SUCCESS; - } - - - public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException { - - logger.info("Mock query2 called " + ctx.getAttribute("j")); - - - return QueryStatus.SUCCESS; - } - - @Override - public QueryStatus reserve(String resource, String select, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException { - - return QueryStatus.SUCCESS; - } - - @Override - public QueryStatus save(String resource, boolean force, boolean localOnly, String key, Map parms, String prefix, SvcLogicContext ctx) throws SvcLogicException { - - logger.info("Mock Save called"); - if (ctx.getAttribute("j").equals("0") && - ctx.getAttribute("k").equals("0") && - "tmp.vnfc-sys-controller".equals(prefix)) { - - assertEquals(resource, "vnfc"); - - assertEquals(key, "'vnfc-name = $request-parameters.vm[$j].vnfc[$k].vnfc-name'"); - - - assertEquals(parms.get("prov-status"), "NVTPROV"); - assertEquals(parms.get("orchestration-status"), "CONFIGURED"); - assertEquals(parms.get("in-maint"), "false"); - assertEquals(parms.get("is-closed-loop"), "false"); - - - assertEquals(parms.get("vnfc-function-code"), "funccode"); - assertEquals(parms.get("vnfc-type"), "vnfctype"); - assertEquals(parms.get("ipaddress-v4-oam-vip"), "135.1.1.1"); - assertEquals(parms.get("group-notation"), "groupnotation"); - - assertEquals(parms.get("relationship-list.relationship[0].related-to"), "vserver"); - assertEquals(parms.get("relationship-list.relationship[0].relationship-data[0].relationship-key"), "vserver.vserver-id"); - assertEquals(parms.get("relationship-list.relationship[0].relationship-data[0].relationship-value"), "vserverid1"); - - - assertEquals(parms.get("relationship-list.relationship[0].relationship-data[1].relationship-key"), "tenant.tenant-id"); - assertEquals(parms.get("relationship-list.relationship[0].relationship-data[1].relationship-value"), "tenantid1"); - - - assertEquals(parms.get("relationship-list.relationship[0].relationship-data[2].relationship-key"), "cloud-region.cloud-owner"); - assertEquals(parms.get("relationship-list.relationship[0].relationship-data[2].relationship-value"), "att-aic"); - - - assertEquals(parms.get("relationship-list.relationship[0].relationship-data[3].relationship-key"), "cloud-region.cloud-region-id"); - assertEquals(parms.get("relationship-list.relationship[0].relationship-data[3].relationship-value"), "cloudregionid1"); - - - assertEquals(parms.get("relationship-list.relationship[1].related-to"), "generic-vnf"); - assertEquals(parms.get("relationship-list.relationship[1].relationship-data[0].relationship-key"), "generic-vnf.vnf-id"); - assertEquals(parms.get("relationship-list.relationship[1].relationship-data[0].relationship-value"), "ibcx0001v"); - - - assertEquals(parms.get("relationship-list.relationship[2].related-to"), "vf-module"); - assertEquals(parms.get("relationship-list.relationship[2].relationship-data[0].relationship-key"), "generic-vnf.vnf-id"); - assertEquals(parms.get("relationship-list.relationship[2].relationship-data[0].relationship-value"), "ibcx0001v"); - - assertEquals(parms.get("relationship-list.relationship[2].relationship-data[1].relationship-key"), "vf-module.vf-module-id"); - assertEquals(parms.get("relationship-list.relationship[2].relationship-data[1].relationship-value"), "1"); - - } - else if (ctx.getAttribute("j").equals("1") && - ctx.getAttribute("k").equals("0") && - "tmp.vnfc-sys-controller".equals(prefix)) { - - assertEquals(resource, "vnfc"); - - assertEquals(key, "'vnfc-name = $request-parameters.vm[$j].vnfc[$k].vnfc-name'"); - - - assertEquals(parms.get("prov-status"), "NVTPROV"); - assertEquals(parms.get("orchestration-status"), "CONFIGURED"); - assertEquals(parms.get("in-maint"), "false"); - assertEquals(parms.get("is-closed-loop"), "false"); - - - assertEquals(parms.get("vnfc-function-code"), "funccode1"); - assertEquals(parms.get("vnfc-type"), "vnfctype1"); - assertEquals(parms.get("ipaddress-v4-oam-vip"), "135.2.2.2"); - assertEquals(parms.get("group-notation"), "groupnotation1"); - - assertEquals(parms.get("relationship-list.relationship[0].related-to"), "vserver"); - assertEquals(parms.get("relationship-list.relationship[0].relationship-data[0].relationship-key"), "vserver.vserver-id"); - assertEquals(parms.get("relationship-list.relationship[0].relationship-data[0].relationship-value"), "vserverid2"); - - - assertEquals(parms.get("relationship-list.relationship[0].relationship-data[1].relationship-key"), "tenant.tenant-id"); - assertEquals(parms.get("relationship-list.relationship[0].relationship-data[1].relationship-value"), "tenantid2"); - - - assertEquals(parms.get("relationship-list.relationship[0].relationship-data[2].relationship-key"), "cloud-region.cloud-owner"); - assertEquals(parms.get("relationship-list.relationship[0].relationship-data[2].relationship-value"), "att-aic"); - - - assertEquals(parms.get("relationship-list.relationship[0].relationship-data[3].relationship-key"), "cloud-region.cloud-region-id"); - assertEquals(parms.get("relationship-list.relationship[0].relationship-data[3].relationship-value"), "cloudregionid2"); - - - assertEquals(parms.get("relationship-list.relationship[1].related-to"), "generic-vnf"); - assertEquals(parms.get("relationship-list.relationship[1].relationship-data[0].relationship-key"), "generic-vnf.vnf-id"); - assertEquals(parms.get("relationship-list.relationship[1].relationship-data[0].relationship-value"), "ibcx0001v"); - - - assertEquals(parms.get("relationship-list.relationship[2].related-to"), "vf-module"); - assertEquals(parms.get("relationship-list.relationship[2].relationship-data[0].relationship-key"), "generic-vnf.vnf-id"); - assertEquals(parms.get("relationship-list.relationship[2].relationship-data[0].relationship-value"), "ibcx0001v"); - - assertEquals(parms.get("relationship-list.relationship[2].relationship-data[1].relationship-key"), "vf-module.vf-module-id"); - assertEquals(parms.get("relationship-list.relationship[2].relationship-data[1].relationship-value"), "1"); - } - return QueryStatus.SUCCESS; - } - - @Override - public QueryStatus release(String resource, String key, SvcLogicContext ctx) throws SvcLogicException { - - return QueryStatus.SUCCESS; - } - - @Override - public QueryStatus delete(String resource, String key, SvcLogicContext ctx) throws SvcLogicException { - - return QueryStatus.SUCCESS; - } - - - - @Override - public QueryStatus notify(String resource, String action, String key, SvcLogicContext ctx) throws SvcLogicException { - - - - return QueryStatus.SUCCESS; - } - - - public QueryStatus update(String resource, String key, - Map parms, String prefix, SvcLogicContext ctx) - throws SvcLogicException { - - return QueryStatus.SUCCESS; - } + private final static Logger logger = LoggerFactory.getLogger(MockAaiResource.class); + + @Override + public QueryStatus isAvailable(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException { + return QueryStatus.SUCCESS; + } + + @Override + public QueryStatus exists(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException { + return QueryStatus.SUCCESS; + } + + public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix, String orderBy, SvcLogicContext ctx) throws SvcLogicException { + if (ctx.getAttribute("j").equals("0") && "tmp.aai-data-vm".equals(prefix)) { + logger.info("Mock VM Get query1 called " + ctx.getAttribute("j") ); + + assertEquals(resource, "vserver"); + assertEquals(key, "'vserver-name = $request-parameters.vm[$j].vm-name'"); + + ctx.setAttribute("tmp.aai-data-vm.vserver-id", "vserverid1"); + + ctx.setAttribute("tmp.aai-data-vm.tenant-id", "tenantid1"); + ctx.setAttribute("tmp.aai-data-vm.cloud-owner", "att-aic"); + ctx.setAttribute("tmp.aai-data-vm.cloud-region-id", "cloudregionid1"); + } + else if (ctx.getAttribute("j").equals("1") && "tmp.aai-data-vm".equals(prefix)) { + logger.info("Mock VM Get query1 called " + ctx.getAttribute("j") ); + + assertEquals(resource, "vserver"); + assertEquals(key, "'vserver-name = $request-parameters.vm[$j].vm-name'"); + + ctx.setAttribute("tmp.aai-data-vm.vserver-id", "vserverid2"); + ctx.setAttribute("tmp.aai-data-vm.tenant-id", "tenantid2"); + ctx.setAttribute("tmp.aai-data-vm.cloud-owner", "att-aic"); + ctx.setAttribute("tmp.aai-data-vm.cloud-region-id", "cloudregionid2"); + } + else if ("tmp.aai-data-vnfc".equals(prefix)) { + logger.info("Mock VNFC Get query1 called " ); + + assertEquals(resource, "vnfc"); + assertEquals(key, "'vnfc-name = $request-parameters.vm[$j].vnfc[$k].vnfc-name'"); + return QueryStatus.NOT_FOUND; + } + return QueryStatus.SUCCESS; + } + + public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException { + logger.info("Mock query2 called " + ctx.getAttribute("j")); + return QueryStatus.SUCCESS; + } + + @Override + public QueryStatus reserve(String resource, String select, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException { + return QueryStatus.SUCCESS; + } + + @Override + public QueryStatus save(String resource, boolean force, boolean localOnly, String key, Map parms, String prefix, SvcLogicContext ctx) throws SvcLogicException { + logger.info("Mock Save called"); + if (ctx.getAttribute("j").equals("0") && + ctx.getAttribute("k").equals("0") && + "tmp.vnfc-sys-controller".equals(prefix)) { + assertEquals(resource, "vnfc"); + assertEquals(key, "'vnfc-name = $request-parameters.vm[$j].vnfc[$k].vnfc-name'"); + assertEquals(parms.get("prov-status"), "NVTPROV"); + assertEquals(parms.get("orchestration-status"), "CONFIGURED"); + assertEquals(parms.get("in-maint"), "false"); + assertEquals(parms.get("is-closed-loop"), "false"); + assertEquals(parms.get("vnfc-function-code"), "funccode"); + assertEquals(parms.get("vnfc-type"), "vnfctype"); + assertEquals(parms.get("ipaddress-v4-oam-vip"), "135.1.1.1"); + assertEquals(parms.get("group-notation"), "groupnotation"); + assertEquals(parms.get("relationship-list.relationship[0].related-to"), "vserver"); + assertEquals(parms.get("relationship-list.relationship[0].relationship-data[0].relationship-key"), "vserver.vserver-id"); + assertEquals(parms.get("relationship-list.relationship[0].relationship-data[0].relationship-value"), "vserverid1"); + assertEquals(parms.get("relationship-list.relationship[0].relationship-data[1].relationship-key"), "tenant.tenant-id"); + assertEquals(parms.get("relationship-list.relationship[0].relationship-data[1].relationship-value"), "tenantid1"); + assertEquals(parms.get("relationship-list.relationship[0].relationship-data[2].relationship-key"), "cloud-region.cloud-owner"); + assertEquals(parms.get("relationship-list.relationship[0].relationship-data[2].relationship-value"), "att-aic"); + assertEquals(parms.get("relationship-list.relationship[0].relationship-data[3].relationship-key"), "cloud-region.cloud-region-id"); + assertEquals(parms.get("relationship-list.relationship[0].relationship-data[3].relationship-value"), "cloudregionid1"); + assertEquals(parms.get("relationship-list.relationship[1].related-to"), "generic-vnf"); + assertEquals(parms.get("relationship-list.relationship[1].relationship-data[0].relationship-key"), "generic-vnf.vnf-id"); + assertEquals(parms.get("relationship-list.relationship[1].relationship-data[0].relationship-value"), "ibcx0001v"); + assertEquals(parms.get("relationship-list.relationship[2].related-to"), "vf-module"); + assertEquals(parms.get("relationship-list.relationship[2].relationship-data[0].relationship-key"), "generic-vnf.vnf-id"); + assertEquals(parms.get("relationship-list.relationship[2].relationship-data[0].relationship-value"), "ibcx0001v"); + assertEquals(parms.get("relationship-list.relationship[2].relationship-data[1].relationship-key"), "vf-module.vf-module-id"); + assertEquals(parms.get("relationship-list.relationship[2].relationship-data[1].relationship-value"), "1"); + } + else if (ctx.getAttribute("j").equals("1") && + ctx.getAttribute("k").equals("0") && + "tmp.vnfc-sys-controller".equals(prefix)) { + assertEquals(resource, "vnfc"); + assertEquals(key, "'vnfc-name = $request-parameters.vm[$j].vnfc[$k].vnfc-name'"); + assertEquals(parms.get("prov-status"), "NVTPROV"); + assertEquals(parms.get("orchestration-status"), "CONFIGURED"); + assertEquals(parms.get("in-maint"), "false"); + assertEquals(parms.get("is-closed-loop"), "false"); + assertEquals(parms.get("vnfc-function-code"), "funccode1"); + assertEquals(parms.get("vnfc-type"), "vnfctype1"); + assertEquals(parms.get("ipaddress-v4-oam-vip"), "135.2.2.2"); + assertEquals(parms.get("group-notation"), "groupnotation1"); + assertEquals(parms.get("relationship-list.relationship[0].related-to"), "vserver"); + assertEquals(parms.get("relationship-list.relationship[0].relationship-data[0].relationship-key"), "vserver.vserver-id"); + assertEquals(parms.get("relationship-list.relationship[0].relationship-data[0].relationship-value"), "vserverid2"); + assertEquals(parms.get("relationship-list.relationship[0].relationship-data[1].relationship-key"), "tenant.tenant-id"); + assertEquals(parms.get("relationship-list.relationship[0].relationship-data[1].relationship-value"), "tenantid2"); + assertEquals(parms.get("relationship-list.relationship[0].relationship-data[2].relationship-key"), "cloud-region.cloud-owner"); + assertEquals(parms.get("relationship-list.relationship[0].relationship-data[2].relationship-value"), "att-aic"); + assertEquals(parms.get("relationship-list.relationship[0].relationship-data[3].relationship-key"), "cloud-region.cloud-region-id"); + assertEquals(parms.get("relationship-list.relationship[0].relationship-data[3].relationship-value"), "cloudregionid2"); + assertEquals(parms.get("relationship-list.relationship[1].related-to"), "generic-vnf"); + assertEquals(parms.get("relationship-list.relationship[1].relationship-data[0].relationship-key"), "generic-vnf.vnf-id"); + assertEquals(parms.get("relationship-list.relationship[1].relationship-data[0].relationship-value"), "ibcx0001v"); + assertEquals(parms.get("relationship-list.relationship[2].related-to"), "vf-module"); + assertEquals(parms.get("relationship-list.relationship[2].relationship-data[0].relationship-key"), "generic-vnf.vnf-id"); + assertEquals(parms.get("relationship-list.relationship[2].relationship-data[0].relationship-value"), "ibcx0001v"); + assertEquals(parms.get("relationship-list.relationship[2].relationship-data[1].relationship-key"), "vf-module.vf-module-id"); + assertEquals(parms.get("relationship-list.relationship[2].relationship-data[1].relationship-value"), "1"); + } + return QueryStatus.SUCCESS; + } + + @Override + public QueryStatus release(String resource, String key, SvcLogicContext ctx) throws SvcLogicException { + return QueryStatus.SUCCESS; + } + + @Override + public QueryStatus delete(String resource, String key, SvcLogicContext ctx) throws SvcLogicException { + return QueryStatus.SUCCESS; + } + + @Override + public QueryStatus notify(String resource, String action, String key, SvcLogicContext ctx) throws SvcLogicException { + return QueryStatus.SUCCESS; + } + + public QueryStatus update(String resource, String key, + Map parms, String prefix, SvcLogicContext ctx) + throws SvcLogicException { + return QueryStatus.SUCCESS; + } } diff --git a/appc-directed-graph/appc-dgraph/provider/src/test/java/org/openecomp/appc/dg/mock/instance/MockConfigureNodeExecutor.java b/appc-directed-graph/appc-dgraph/provider/src/test/java/org/openecomp/appc/dg/mock/instance/MockConfigureNodeExecutor.java index 165c39905..bcfd61316 100644 --- a/appc-directed-graph/appc-dgraph/provider/src/test/java/org/openecomp/appc/dg/mock/instance/MockConfigureNodeExecutor.java +++ b/appc-directed-graph/appc-dgraph/provider/src/test/java/org/openecomp/appc/dg/mock/instance/MockConfigureNodeExecutor.java @@ -28,51 +28,44 @@ import org.openecomp.sdnc.sli.SvcLogicContext; public class MockConfigureNodeExecutor implements SvcLogicAdaptor{ - @Override - public ConfigStatus configure(String key, Map parameters, SvcLogicContext ctx) { - - - if ( "get".equals(key)) { - - if ("135.1.1.1".equals(parameters.get("host") )) { - String fullPathFileName = parameters.get("fullPathFileName"); - if (("SuccessFile").equals(fullPathFileName ) ) - return ConfigStatus.FAILURE; - if (("FailureFile").equals(fullPathFileName ) ) - return ConfigStatus.SUCCESS; - if (("FailureLogFile").equals(fullPathFileName ) ) - return ConfigStatus.SUCCESS; - } - else if ("135.2.2.2".equals(parameters.get("host")) ) { - String fullPathFileName = parameters.get("fullPathFileName"); - if (("SuccessFile").equals(fullPathFileName ) ) - return ConfigStatus.FAILURE; - if (("FailureFile").equals(fullPathFileName ) ) - return ConfigStatus.FAILURE; - - } - - return ConfigStatus.SUCCESS; - } - else { - ctx.setAttribute("Status", "Success"); - - return ConfigStatus.SUCCESS; - } - } + @Override + public ConfigStatus configure(String key, Map parameters, SvcLogicContext ctx) { - @Override - public ConfigStatus activate(String key, SvcLogicContext ctx) { - // TODO Auto-generated method stub - return null; - } + if ( "get".equals(key)) { - @Override - public ConfigStatus deactivate(String key, SvcLogicContext ctx) { - // TODO Auto-generated method stub - return null; - } + if ("135.1.1.1".equals(parameters.get("host") )) { + String fullPathFileName = parameters.get("fullPathFileName"); + if (("SuccessFile").equals(fullPathFileName ) ) + return ConfigStatus.FAILURE; + if (("FailureFile").equals(fullPathFileName ) ) + return ConfigStatus.SUCCESS; + if (("FailureLogFile").equals(fullPathFileName ) ) + return ConfigStatus.SUCCESS; + } + else if ("135.2.2.2".equals(parameters.get("host")) ) { + String fullPathFileName = parameters.get("fullPathFileName"); + if (("SuccessFile").equals(fullPathFileName ) ) + return ConfigStatus.FAILURE; + if (("FailureFile").equals(fullPathFileName ) ) + return ConfigStatus.FAILURE; + } + return ConfigStatus.SUCCESS; + } + else { + ctx.setAttribute("Status", "Success"); + return ConfigStatus.SUCCESS; + } + } + @Override + public ConfigStatus activate(String key, SvcLogicContext ctx) { + return null; + } + + @Override + public ConfigStatus deactivate(String key, SvcLogicContext ctx) { + return null; + } } diff --git a/appc-directed-graph/appc-dgraph/provider/src/test/java/org/openecomp/appc/dg/mock/instance/MockSvcLogicJavaPlugin.java b/appc-directed-graph/appc-dgraph/provider/src/test/java/org/openecomp/appc/dg/mock/instance/MockSvcLogicJavaPlugin.java index e13212600..9bf7e412e 100644 --- a/appc-directed-graph/appc-dgraph/provider/src/test/java/org/openecomp/appc/dg/mock/instance/MockSvcLogicJavaPlugin.java +++ b/appc-directed-graph/appc-dgraph/provider/src/test/java/org/openecomp/appc/dg/mock/instance/MockSvcLogicJavaPlugin.java @@ -33,116 +33,74 @@ import org.openecomp.sdnc.sli.SvcLogicException; import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; public class MockSvcLogicJavaPlugin implements SvcLogicJavaPlugin{ - private final static Logger logger = LoggerFactory.getLogger(MockSvcLogicJavaPlugin.class); - public static String INPUT_PARAM_RESPONSE_PREFIX = "responsePrefix"; - public static String OUTPUT_STATUS_SUCCESS = "success"; - public static String OUTPUT_STATUS_FAILURE = "failure"; - public static String OUTPUT_PARAM_STATUS = "status"; - - - public void mountDevice(Map inParams, SvcLogicContext ctx) throws SvcLogicException{ - logger.info("Executed MountDevice Plugin"); - } - - public void downloadDeviceConfiguration(Map inParams, SvcLogicContext ctx) throws SvcLogicException{ - ctx.setAttribute("downloadStatus", "success"); - logger.info("Executed Download Device Configuration Plugin"); - throw new SvcLogicException("failed in Download.."); - } - - - - - public void getCommonConfigInfo(Map inParams, SvcLogicContext ctx) throws SvcLogicException, FileNotFoundException, IOException { - logger.info("Mock getCommonConfigInfo Called...."); - - - /*** - ctx.setAttribute("device-authentication.USER-NAME", "root"); - - String responsePrefix = inParams.get(INPUT_PARAM_RESPONSE_PREFIX); - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; - - - ctx.setAttribute(responsePrefix +OUTPUT_PARAM_STATUS, - OUTPUT_STATUS_SUCCESS); - - **/ - - } - - - public void getConfigFileReference(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - logger.info("Mock getConfigFileReference Called...."); - } - - - - public void getTemplate(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - logger.info("Mock getTemplate Called...."); - } - - - - public void saveConfigFiles(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - logger.info("Mock saveConfigFiles called..."); - - } - - - - public void updateUploadConfig(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - logger.info("Mock updateUploadConfig called..."); - } - - - - - public void savePrepareRelationship(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - logger.info("Mock savePrepareRelationship called..."); - } - - - - - - public void saveConfigBlock(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - logger.info("Mock saveConfigBlock called..."); - - if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) { - logger.info("No params..."); - ctx.setAttribute("file-category", "device_configuration"); - ctx.setAttribute("deviceconfig-file-content", "deviceConfig"); - - } else { - logger.info("Config params exist..."); - ctx.setAttribute("file-category", "device_configuration"); - ctx.setAttribute("file-category1", "configuration_block"); - ctx.setAttribute("file-category2", "config_data"); - - } - - } - - public void saveTemplateConfig(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - logger.info("Mock saveTemplateConfig called..."); - - if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) { - logger.info("No params..."); - ctx.setAttribute("file-category", "device_configuration"); - ctx.setAttribute("deviceconfig-file-content", "deviceConfig"); - - } else { - logger.info("Config params exist..."); - ctx.setAttribute("file-category", "device_configuration"); - ctx.setAttribute("file-category1", "config_data"); - - } - - - } + private final static Logger logger = LoggerFactory.getLogger(MockSvcLogicJavaPlugin.class); + public static String INPUT_PARAM_RESPONSE_PREFIX = "responsePrefix"; + public static String OUTPUT_STATUS_SUCCESS = "success"; + public static String OUTPUT_STATUS_FAILURE = "failure"; + public static String OUTPUT_PARAM_STATUS = "status"; + + + public void mountDevice(Map inParams, SvcLogicContext ctx) throws SvcLogicException{ + logger.info("Executed MountDevice Plugin"); + } + + public void downloadDeviceConfiguration(Map inParams, SvcLogicContext ctx) throws SvcLogicException{ + ctx.setAttribute("downloadStatus", "success"); + logger.info("Executed Download Device Configuration Plugin"); + throw new SvcLogicException("failed in Download.."); + } + + public void getCommonConfigInfo(Map inParams, SvcLogicContext ctx) throws SvcLogicException, FileNotFoundException, IOException { + logger.info("Mock getCommonConfigInfo Called...."); + } + + public void getConfigFileReference(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + logger.info("Mock getConfigFileReference Called...."); + } + + public void getTemplate(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + logger.info("Mock getTemplate Called...."); + } + + public void saveConfigFiles(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + logger.info("Mock saveConfigFiles called..."); + } + + public void updateUploadConfig(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + logger.info("Mock updateUploadConfig called..."); + } + + public void savePrepareRelationship(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + logger.info("Mock savePrepareRelationship called..."); + } + + public void saveConfigBlock(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + logger.info("Mock saveConfigBlock called..."); + + if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) { + logger.info("No params..."); + ctx.setAttribute("file-category", "device_configuration"); + ctx.setAttribute("deviceconfig-file-content", "deviceConfig"); + } else { + logger.info("Config params exist..."); + ctx.setAttribute("file-category", "device_configuration"); + ctx.setAttribute("file-category1", "configuration_block"); + ctx.setAttribute("file-category2", "config_data"); + } + } + + public void saveTemplateConfig(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + logger.info("Mock saveTemplateConfig called..."); + + if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) { + logger.info("No params..."); + ctx.setAttribute("file-category", "device_configuration"); + ctx.setAttribute("deviceconfig-file-content", "deviceConfig"); + + } else { + logger.info("Config params exist..."); + ctx.setAttribute("file-category", "device_configuration"); + ctx.setAttribute("file-category1", "config_data"); + } + } } diff --git a/appc-directed-graph/appc-dgraph/provider/src/test/resources/properties/APPC/PublishConfiguration/PublishConfig_Failure.properties b/appc-directed-graph/appc-dgraph/provider/src/test/resources/properties/APPC/PublishConfiguration/PublishConfig_Failure.properties index 4e2dccfd5..2a84acc81 100644 --- a/appc-directed-graph/appc-dgraph/provider/src/test/resources/properties/APPC/PublishConfiguration/PublishConfig_Failure.properties +++ b/appc-directed-graph/appc-dgraph/provider/src/test/resources/properties/APPC/PublishConfiguration/PublishConfig_Failure.properties @@ -17,6 +17,7 @@ # limitations under the License. # ============LICENSE_END========================================================= ### + input.vnf-id=ibcx0001v input.tmp.uploadConfigInfo.VNF-ID=ibcx0001v input.tmp.uploadConfigInfo.UPLOAD-CONFIG-ID=12434 diff --git a/appc-directed-graph/appc-dgraph/provider/src/test/resources/properties/APPC/PublishConfiguration/PublishConfig_Success.properties b/appc-directed-graph/appc-dgraph/provider/src/test/resources/properties/APPC/PublishConfiguration/PublishConfig_Success.properties index bf851ed37..a1e160fb0 100644 --- a/appc-directed-graph/appc-dgraph/provider/src/test/resources/properties/APPC/PublishConfiguration/PublishConfig_Success.properties +++ b/appc-directed-graph/appc-dgraph/provider/src/test/resources/properties/APPC/PublishConfiguration/PublishConfig_Success.properties @@ -17,6 +17,7 @@ # limitations under the License. # ============LICENSE_END========================================================= ### + input.vnf-id=ibcx0001v input.tmp.uploadConfigInfo.VNF-ID=ibcx0001v input.tmp.uploadConfigInfo.UPLOAD-CONFIG-ID=12434 diff --git a/appc-directed-graph/dg-loader/features/src/main/resources/features.xml b/appc-directed-graph/dg-loader/features/src/main/resources/features.xml index 2d4a65438..49bf35811 100644 --- a/appc-directed-graph/dg-loader/features/src/main/resources/features.xml +++ b/appc-directed-graph/dg-loader/features/src/main/resources/features.xml @@ -20,6 +20,7 @@ --> + diff --git a/appc-directed-graph/dg-loader/pom.xml b/appc-directed-graph/dg-loader/pom.xml index 557969331..40b3b90ec 100644 --- a/appc-directed-graph/dg-loader/pom.xml +++ b/appc-directed-graph/dg-loader/pom.xml @@ -1,4 +1,27 @@ + @@ -31,45 +54,9 @@ 1.1.0 1.1.0 1.1.0 + ${project.parent.parent.basedir} - - - - - org.openecomp.appc.plugins - dg-loader.features - features - xml - ${project.version} - - - - org.openecomp.appc.plugins - dg-loader.provider - ${project.version} - - - - org.openecomp.sdnc.core - sli-common - ${sdnctl.sli.version} - - - - org.openecomp.sdnc.core - sli-provider - - - - org.openecomp.sdnc.core - dblib-provider - ${sdnctl.dblib.version} - - - - - features provider diff --git a/appc-directed-graph/dg-loader/provider/pom.xml b/appc-directed-graph/dg-loader/provider/pom.xml index 3bd0ae9d2..587c92aae 100644 --- a/appc-directed-graph/dg-loader/provider/pom.xml +++ b/appc-directed-graph/dg-loader/provider/pom.xml @@ -1,4 +1,27 @@ + 4.0.0 @@ -9,8 +32,7 @@ dg-loader-provider bundle - Directed Graph Loader - Provider - http://maven.apache.org + APPC Directed Graph Loader - Provider @@ -22,25 +44,20 @@ commons-io commons-io - ${common.io.version} com.att.eelf eelf-core - ${eelf.version} - junit junit test - - org.apache.felix maven-bundle-plugin diff --git a/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGLoaderActivator.java b/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGLoaderActivator.java index dd56e6cc1..99f7f8b6c 100644 --- a/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGLoaderActivator.java +++ b/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGLoaderActivator.java @@ -32,27 +32,27 @@ import com.att.eelf.configuration.EELFManager; public class DGLoaderActivator implements BundleActivator{ - private List registrations = new LinkedList(); + private List registrations = new LinkedList(); - private static final EELFLogger log = EELFManager.getInstance().getLogger(DGLoaderActivator.class); + private static final EELFLogger log = EELFManager.getInstance().getLogger(DGLoaderActivator.class); - @Override - public void start(BundleContext ctx) throws Exception - { + @Override + public void start(BundleContext ctx) throws Exception + { - + - } - @Override - public void stop(BundleContext arg0) throws Exception - { - for (ServiceRegistration registration: registrations) - { - registration.unregister(); - registration = null; - } + } + @Override + public void stop(BundleContext arg0) throws Exception + { + for (ServiceRegistration registration: registrations) + { + registration.unregister(); + registration = null; + } - } + } } diff --git a/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLActivate.java b/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLActivate.java index 1cb446a83..b37400ba7 100644 --- a/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLActivate.java +++ b/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLActivate.java @@ -36,93 +36,90 @@ import org.slf4j.LoggerFactory; public class DGXMLActivate { - private final static Logger logger = LoggerFactory.getLogger(DGXMLLoadNActivate.class); - private final SvcLogicStore store; - public static String STRING_ENCODING = "utf-8"; - - public DGXMLActivate(String propfile) throws Exception{ - if(StringUtils.isBlank(propfile)){ - throw new Exception(propfile + " Profile file is not defined"); - } - this.store = SvcLogicStoreFactory.getSvcLogicStore(propfile); - } - - - public void activateDg(String activateFilePath) throws Exception { - logger.info("******************** Activating DG into Database *****************************"); - try { - List errors = new ArrayList(); - if(this.store != null){ - File activateFile = new File(activateFilePath); - if(activateFile != null && activateFile.isFile()){ - List fileLines = FileUtils.readLines(activateFile,STRING_ENCODING); - if(fileLines != null ){ - for (String line : fileLines) { - if(line != null && ! line.trim().startsWith("#")){ - String lineArray[] = line.trim().split(":"); - try { - if(lineArray != null && lineArray.length >= 4){ - String module = lineArray[0]; - String rpc = lineArray[1]; - String version = lineArray[2]; - String mode = lineArray[3]; - if(StringUtils.isNotBlank(module) && StringUtils.isNotBlank(rpc) - && StringUtils.isNotBlank(version) && StringUtils.isNotBlank(mode)){ - logger.info("Activating DG :" + line); - SvcLogicGraph graph = this.store.fetch(module, rpc, version, mode); - if(graph != null){ - logger.info("Found Graph :" + line + " Activating ..."); - this.store.activate(graph); - }else{ - throw new Exception("Failed to fetch from Database"); - } - } - } - } catch (Exception e) { - e.printStackTrace(); - errors.add("Failed to Activate "+line + ", "+e.getMessage()); - } - } - } - } - }else{ - throw new Exception(activateFile + " is not a valid Activate file Path"); - } - }else{ - throw new Exception("Failed to initialise SvcLogicStore"); - } - - if(errors.size() > 0){ - throw new Exception(errors.toString()); - } - } catch (Exception e) { - logger.error(e.getMessage()); - } - } - - - public static void main(String[] args) { - try { - - String activateFile = null; - String propertyPath = null; - - if(args != null && args.length >= 2){ - activateFile = args[0]; - propertyPath = args[1]; - }else{ - throw new Exception("Sufficient inputs for DGXMLActivate are missing "); - } - - DGXMLActivate dgXmlActivate = new DGXMLActivate(propertyPath); - dgXmlActivate.activateDg(activateFile); - } catch (Exception e) { - e.printStackTrace(); - }finally { - System.exit(1); - } - } - - + private final static Logger logger = LoggerFactory.getLogger(DGXMLLoadNActivate.class); + private final SvcLogicStore store; + public static String STRING_ENCODING = "utf-8"; + + public DGXMLActivate(String propfile) throws Exception{ + if(StringUtils.isBlank(propfile)){ + throw new Exception(propfile + " Profile file is not defined"); + } + this.store = SvcLogicStoreFactory.getSvcLogicStore(propfile); + } + + + public void activateDg(String activateFilePath) throws Exception { + logger.info("******************** Activating DG into Database *****************************"); + try { + List errors = new ArrayList(); + if(this.store != null){ + File activateFile = new File(activateFilePath); + if(activateFile != null && activateFile.isFile()){ + List fileLines = FileUtils.readLines(activateFile,STRING_ENCODING); + if(fileLines != null ){ + for (String line : fileLines) { + if(line != null && ! line.trim().startsWith("#")){ + String lineArray[] = line.trim().split(":"); + try { + if(lineArray != null && lineArray.length >= 4){ + String module = lineArray[0]; + String rpc = lineArray[1]; + String version = lineArray[2]; + String mode = lineArray[3]; + if(StringUtils.isNotBlank(module) && StringUtils.isNotBlank(rpc) + && StringUtils.isNotBlank(version) && StringUtils.isNotBlank(mode)){ + logger.info("Activating DG :" + line); + SvcLogicGraph graph = this.store.fetch(module, rpc, version, mode); + if(graph != null){ + logger.info("Found Graph :" + line + " Activating ..."); + this.store.activate(graph); + }else{ + throw new Exception("Failed to fetch from Database"); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + errors.add("Failed to Activate "+line + ", "+e.getMessage()); + } + } + } + } + }else{ + throw new Exception(activateFile + " is not a valid Activate file Path"); + } + }else{ + throw new Exception("Failed to initialise SvcLogicStore"); + } + + if(errors.size() > 0){ + throw new Exception(errors.toString()); + } + } catch (Exception e) { + logger.error(e.getMessage()); + } + } + + + public static void main(String[] args) { + try { + String activateFile = null; + String propertyPath = null; + + if(args != null && args.length >= 2){ + activateFile = args[0]; + propertyPath = args[1]; + }else{ + throw new Exception("Sufficient inputs for DGXMLActivate are missing "); + } + + DGXMLActivate dgXmlActivate = new DGXMLActivate(propertyPath); + dgXmlActivate.activateDg(activateFile); + } catch (Exception e) { + e.printStackTrace(); + }finally { + System.exit(1); + } + } } diff --git a/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLGenerator.java b/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLGenerator.java index 3ffef14fe..60fcd5ba8 100644 --- a/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLGenerator.java +++ b/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLGenerator.java @@ -34,95 +34,95 @@ import org.slf4j.LoggerFactory; public class DGXMLGenerator { - private final static Logger logger = LoggerFactory.getLogger(DGXMLGenerator.class); - - public static String STRING_ENCODING = "utf-8"; - public static String JS_INTERFACE_DG_CONVERTOR = "dgconverter"; - public static String JS_METHOD_GET_NODE_TO_XML = "getNodeToXml"; - public static String GENERATOR_TEMPLATE_FILE = "js/dg_xml2json.js"; - - public void generateXMLFromJSON(String jsonPath, String xmlpath, String propertyPath) throws Exception { - try{ - ScriptEngineManager manager = new ScriptEngineManager(); - ScriptEngine engine = manager.getEngineByName("JavaScript"); - if (!(engine instanceof Invocable)) { - logger.error("Invoking methods is not supported."); - return; - } - Invocable inv = (Invocable) engine; - // engine.eval(new FileReader(DGXMLGenerator.class.getClassLoader().getResource(GENERATOR_TEMPLATE_FILE).getPath())); - String js = IOUtils.toString(DGXMLGenerator.class.getClassLoader().getResourceAsStream(GENERATOR_TEMPLATE_FILE),STRING_ENCODING); - engine.eval(js); - - Object dgconverter = engine.get(JS_INTERFACE_DG_CONVERTOR); - - List files = new ArrayList(); - if(dgconverter != null){ - File jsonPathFile = new File(jsonPath); - if(jsonPathFile.isDirectory()){ - String[] extensions = new String[] { "json", "JSON" }; - files = (List) FileUtils.listFiles(jsonPathFile, extensions, true); - }else if(jsonPathFile.isFile()){ - files.add(jsonPathFile); - }else{ - throw new Exception("Failed to get the nature of the JSON path :"+ jsonPath); - } - - logger.info("JSON Files identified "+ files.size()); - - if(files.size() > 0){ - boolean isXmlPathDeleted = FileUtils.deleteQuietly(new File(xmlpath)); - logger.info("Cleaning old DG XML under : " + xmlpath + ", delete status :" + isXmlPathDeleted); - - for (File file : files) { - String dgJson = FileUtils.readFileToString(file,STRING_ENCODING); - logger.info("Generating XML from :" + file.getName()); - String xmlFileName = xmlpath +"/"+file.getName().replace(".json", ".xml"); - - Object dgXMl = inv.invokeMethod(dgconverter, JS_METHOD_GET_NODE_TO_XML, dgJson); - // Write the XML File - if(dgXMl != null){ - File xmlFile = new File(xmlFileName); - FileUtils.writeStringToFile(xmlFile, dgXMl.toString(), STRING_ENCODING); - logger.info("Generated XML File under :" + xmlFile.getCanonicalPath()); - } - } - - }else{ - logger.info("No JSON Files to generate XML"); - } - }else{ - logger.error("Couldn't get Java Script Engine.."); - } - }catch (Exception e) { - logger.error("Failed to generate generateXMLFromJSON :"+e.getMessage()); - } - } - - - public static void main(String[] args) { - try { - DGXMLGenerator application = new DGXMLGenerator(); - String jsonPath = null; - String xmlPath = null; - String propertyPath = null; - // Generate, GenerateLoad, GenerateLoadActivate - //args = new String[]{"src/main/resources/json","src/test/resources/xml"}; - logger.info("DGXML Conversion Started with arguments :"+ args[0] +":"+ args[1]); - if(args != null && args.length >= 2){ - jsonPath = args[0]; - xmlPath = args[1]; - }else{ - throw new Exception("Sufficient inputs are missing "); - } - - application.generateXMLFromJSON(jsonPath, xmlPath, propertyPath); - logger.info("DGXML Conversion Completed..."); - } catch (Exception e) { - logger.error("Failed in DG XML Generation :"+e.getMessage()); - e.printStackTrace(); - } - - } + private final static Logger logger = LoggerFactory.getLogger(DGXMLGenerator.class); + + public static String STRING_ENCODING = "utf-8"; + public static String JS_INTERFACE_DG_CONVERTOR = "dgconverter"; + public static String JS_METHOD_GET_NODE_TO_XML = "getNodeToXml"; + public static String GENERATOR_TEMPLATE_FILE = "js/dg_xml2json.js"; + + public void generateXMLFromJSON(String jsonPath, String xmlpath, String propertyPath) throws Exception { + try{ + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine engine = manager.getEngineByName("JavaScript"); + if (!(engine instanceof Invocable)) { + logger.error("Invoking methods is not supported."); + return; + } + Invocable inv = (Invocable) engine; + // engine.eval(new FileReader(DGXMLGenerator.class.getClassLoader().getResource(GENERATOR_TEMPLATE_FILE).getPath())); + String js = IOUtils.toString(DGXMLGenerator.class.getClassLoader().getResourceAsStream(GENERATOR_TEMPLATE_FILE),STRING_ENCODING); + engine.eval(js); + + Object dgconverter = engine.get(JS_INTERFACE_DG_CONVERTOR); + + List files = new ArrayList(); + if(dgconverter != null){ + File jsonPathFile = new File(jsonPath); + if(jsonPathFile.isDirectory()){ + String[] extensions = new String[] { "json", "JSON" }; + files = (List) FileUtils.listFiles(jsonPathFile, extensions, true); + }else if(jsonPathFile.isFile()){ + files.add(jsonPathFile); + }else{ + throw new Exception("Failed to get the nature of the JSON path :"+ jsonPath); + } + + logger.info("JSON Files identified "+ files.size()); + + if(files.size() > 0){ + boolean isXmlPathDeleted = FileUtils.deleteQuietly(new File(xmlpath)); + logger.info("Cleaning old DG XML under : " + xmlpath + ", delete status :" + isXmlPathDeleted); + + for (File file : files) { + String dgJson = FileUtils.readFileToString(file,STRING_ENCODING); + logger.info("Generating XML from :" + file.getName()); + String xmlFileName = xmlpath +"/"+file.getName().replace(".json", ".xml"); + + Object dgXMl = inv.invokeMethod(dgconverter, JS_METHOD_GET_NODE_TO_XML, dgJson); + // Write the XML File + if(dgXMl != null){ + File xmlFile = new File(xmlFileName); + FileUtils.writeStringToFile(xmlFile, dgXMl.toString(), STRING_ENCODING); + logger.info("Generated XML File under :" + xmlFile.getCanonicalPath()); + } + } + + }else{ + logger.info("No JSON Files to generate XML"); + } + }else{ + logger.error("Couldn't get Java Script Engine.."); + } + }catch (Exception e) { + logger.error("Failed to generate generateXMLFromJSON :"+e.getMessage()); + } + } + + + public static void main(String[] args) { + try { + DGXMLGenerator application = new DGXMLGenerator(); + String jsonPath = null; + String xmlPath = null; + String propertyPath = null; + // Generate, GenerateLoad, GenerateLoadActivate + //args = new String[]{"src/main/resources/json","src/test/resources/xml"}; + logger.info("DGXML Conversion Started with arguments :"+ args[0] +":"+ args[1]); + if(args != null && args.length >= 2){ + jsonPath = args[0]; + xmlPath = args[1]; + }else{ + throw new Exception("Sufficient inputs are missing "); + } + + application.generateXMLFromJSON(jsonPath, xmlPath, propertyPath); + logger.info("DGXML Conversion Completed..."); + } catch (Exception e) { + logger.error("Failed in DG XML Generation :"+e.getMessage()); + e.printStackTrace(); + } + + } } diff --git a/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLLoad.java b/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLLoad.java index 5e9673079..b7651bbe5 100644 --- a/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLLoad.java +++ b/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLLoad.java @@ -35,80 +35,74 @@ import org.openecomp.sdnc.sli.SvcLogicStore; import org.openecomp.sdnc.sli.SvcLogicStoreFactory; public class DGXMLLoad { - private final static Logger logger = LoggerFactory.getLogger(DGXMLLoad.class); - private final SvcLogicStore store; - public static String STRING_ENCODING = "utf-8"; + private final static Logger logger = LoggerFactory.getLogger(DGXMLLoad.class); + private final SvcLogicStore store; + public static String STRING_ENCODING = "utf-8"; - public DGXMLLoad(String propfile) throws Exception{ - if(StringUtils.isBlank(propfile)){ - throw new Exception(propfile + " Profile file is not defined"); - } - this.store = SvcLogicStoreFactory.getSvcLogicStore(propfile); - } + public DGXMLLoad(String propfile) throws Exception{ + if(StringUtils.isBlank(propfile)){ + throw new Exception(propfile + " Profile file is not defined"); + } + this.store = SvcLogicStoreFactory.getSvcLogicStore(propfile); + } - public void loadDGXMLFile(String dgXMLpath) throws SvcLogicException{ - if(dgXMLpath != null ){ - SvcLogicParser.load(dgXMLpath, this.store); - } - } + public void loadDGXMLFile(String dgXMLpath) throws SvcLogicException{ + if(dgXMLpath != null ){ + SvcLogicParser.load(dgXMLpath, this.store); + } + } - private void loadDGXMLDir(String xmlPath) throws Exception { - try { - logger.info("******************** Loading DG into Database *****************************"); - List errors = new ArrayList(); - if(this.store != null){ - File xmlDir = new File(xmlPath); - if(xmlDir != null && xmlDir.isDirectory()){ - String[] extensions = new String[] { "xml", "XML" }; - List files = (List) FileUtils.listFiles(xmlDir, extensions, true); - for (File file : files) { - logger.info("Loading DG XML file :" + file.getCanonicalPath()); - try{ - SvcLogicParser.load(file.getCanonicalPath(), this.store); - }catch (Exception e) { - errors.add("Failed to load XML "+file.getCanonicalPath() + ", Exception : "+e.getMessage()); - } - } - }else{ - throw new Exception(xmlPath + " is not a valid XML Directory"); - } - }else{ - throw new Exception("Failed to initialise SvcLogicStore"); - } + private void loadDGXMLDir(String xmlPath) throws Exception { + try { + logger.info("******************** Loading DG into Database *****************************"); + List errors = new ArrayList(); + if(this.store != null){ + File xmlDir = new File(xmlPath); + if(xmlDir != null && xmlDir.isDirectory()){ + String[] extensions = new String[] { "xml", "XML" }; + List files = (List) FileUtils.listFiles(xmlDir, extensions, true); + for (File file : files) { + logger.info("Loading DG XML file :" + file.getCanonicalPath()); + try{ + SvcLogicParser.load(file.getCanonicalPath(), this.store); + }catch (Exception e) { + errors.add("Failed to load XML "+file.getCanonicalPath() + ", Exception : "+e.getMessage()); + } + } + }else{ + throw new Exception(xmlPath + " is not a valid XML Directory"); + } + }else{ + throw new Exception("Failed to initialise SvcLogicStore"); + } - if(errors.size() > 0){ - throw new Exception(errors.toString()); - } - } catch (Exception e) { - logger.error(e.getMessage()); - } - } + if(errors.size() > 0){ + throw new Exception(errors.toString()); + } + } catch (Exception e) { + logger.error(e.getMessage()); + } + } - + public static void main(String[] args) { + try { + String xmlPath = null; + String propertyPath = null; + if(args != null && args.length >= 2){ + xmlPath = args[0]; + propertyPath = args[1]; + }else{ + throw new Exception("Sufficient inputs for DGXMLLoadNActivate are missing "); + } - public static void main(String[] args) { - try { - String xmlPath = null; - String propertyPath = null; - - if(args != null && args.length >= 2){ - xmlPath = args[0]; - propertyPath = args[1]; - }else{ - throw new Exception("Sufficient inputs for DGXMLLoadNActivate are missing "); - } - - //propertyPath = "/Users/bs2796/0Source/ecomp/bvc-3.2.2/others/properties/dblib.properties"; - //xmlPath = DGXMLLoadNActivate.class.getClassLoader().getResource(".").getPath() +"/xml" ; - - DGXMLLoad dgXMLLoadDB = new DGXMLLoad(propertyPath); - dgXMLLoadDB.loadDGXMLDir(xmlPath); - } catch (Exception e) { - e.printStackTrace(); - }finally { - System.exit(1); - } - } + DGXMLLoad dgXMLLoadDB = new DGXMLLoad(propertyPath); + dgXMLLoadDB.loadDGXMLDir(xmlPath); + } catch (Exception e) { + e.printStackTrace(); + }finally { + System.exit(1); + } + } } diff --git a/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLLoadNActivate.java b/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLLoadNActivate.java index 1373143cf..f5eb2441f 100644 --- a/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLLoadNActivate.java +++ b/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLLoadNActivate.java @@ -36,133 +36,133 @@ import org.openecomp.sdnc.sli.SvcLogicStore; import org.openecomp.sdnc.sli.SvcLogicStoreFactory; public class DGXMLLoadNActivate { - private final static Logger logger = LoggerFactory.getLogger(DGXMLLoadNActivate.class); - private final SvcLogicStore store; - public static String STRING_ENCODING = "utf-8"; - - public DGXMLLoadNActivate(String propfile) throws Exception{ - if(StringUtils.isBlank(propfile)){ - throw new Exception(propfile + " Profile file is not defined"); - } - this.store = SvcLogicStoreFactory.getSvcLogicStore(propfile); - } - - public void loadDGXMLFile(String dgXMLpath) throws SvcLogicException{ - if(dgXMLpath != null ){ - SvcLogicParser.load(dgXMLpath, this.store); - } - } - - private void loadDGXMLDir(String xmlPath) throws Exception { - try { - logger.info("******************** Loading DG into Database *****************************"); - List errors = new ArrayList(); - if(this.store != null){ - File xmlDir = new File(xmlPath); - if(xmlDir != null && xmlDir.isDirectory()){ - String[] extensions = new String[] { "xml", "XML" }; - List files = (List) FileUtils.listFiles(xmlDir, extensions, true); - for (File file : files) { - logger.info("Loading DG XML file :" + file.getCanonicalPath()); - try{ - SvcLogicParser.load(file.getCanonicalPath(), this.store); - }catch (Exception e) { - errors.add("Failed to load XML "+file.getCanonicalPath() + ", Exception : "+e.getMessage()); - } - } - }else{ - throw new Exception(xmlPath + " is not a valid XML Directory"); - } - }else{ - throw new Exception("Failed to initialise SvcLogicStore"); - } - - if(errors.size() > 0){ - throw new Exception(errors.toString()); - } - } catch (Exception e) { - logger.error(e.getMessage()); - } - } - - public void activateDg(String activateFilePath) throws Exception { - logger.info("******************** Activating DG into Database *****************************"); - try { - List errors = new ArrayList(); - if(this.store != null){ - File activateFile = new File(activateFilePath); - if(activateFile != null && activateFile.isFile()){ - List fileLines = FileUtils.readLines(activateFile,STRING_ENCODING); - if(fileLines != null ){ - for (String line : fileLines) { - if(line != null && ! line.trim().startsWith("#")){ - String lineArray[] = line.trim().split(":"); - try { - if(lineArray != null && lineArray.length >= 4){ - String module = lineArray[0]; - String rpc = lineArray[1]; - String version = lineArray[2]; - String mode = lineArray[3]; - if(StringUtils.isNotBlank(module) && StringUtils.isNotBlank(rpc) - && StringUtils.isNotBlank(version) && StringUtils.isNotBlank(mode)){ - logger.info("Activating DG :" + line); - SvcLogicGraph graph = this.store.fetch(module, rpc, version, mode); - if(graph != null){ - logger.info("Found Graph :" + line + " Activating ..."); - this.store.activate(graph); - }else{ - throw new Exception("Failed to fetch from Database"); - } - } - } - } catch (Exception e) { - e.printStackTrace(); - errors.add("Failed to Activate "+line + ", "+e.getMessage()); - } - } - } - } - }else{ - throw new Exception(activateFile + " is not a valid Activate file Path"); - } - }else{ - throw new Exception("Failed to initialise SvcLogicStore"); - } - - if(errors.size() > 0){ - throw new Exception(errors.toString()); - } - } catch (Exception e) { - logger.error(e.getMessage()); - } - } - - - public static void main(String[] args) { - try { - String xmlPath = null; - String propertyPath = null; - String activateFile = null; - - if(args != null && args.length >= 3){ - xmlPath = args[0]; - activateFile = args[1]; - propertyPath = args[2]; - }else{ - throw new Exception("Sufficient inputs for DGXMLLoadNActivate are missing "); - } - - //propertyPath = "/Users/bs2796/0Source/ecomp/bvc-3.2.2/others/properties/dblib.properties"; - //xmlPath = DGXMLLoadNActivate.class.getClassLoader().getResource(".").getPath() +"/xml" ; - - DGXMLLoadNActivate dgXMLLoadDB = new DGXMLLoadNActivate(propertyPath); - dgXMLLoadDB.loadDGXMLDir(xmlPath); - dgXMLLoadDB.activateDg(activateFile); - } catch (Exception e) { - e.printStackTrace(); - }finally { - System.exit(1); - } - } + private final static Logger logger = LoggerFactory.getLogger(DGXMLLoadNActivate.class); + private final SvcLogicStore store; + public static String STRING_ENCODING = "utf-8"; + + public DGXMLLoadNActivate(String propfile) throws Exception{ + if(StringUtils.isBlank(propfile)){ + throw new Exception(propfile + " Profile file is not defined"); + } + this.store = SvcLogicStoreFactory.getSvcLogicStore(propfile); + } + + public void loadDGXMLFile(String dgXMLpath) throws SvcLogicException{ + if(dgXMLpath != null ){ + SvcLogicParser.load(dgXMLpath, this.store); + } + } + + private void loadDGXMLDir(String xmlPath) throws Exception { + try { + logger.info("******************** Loading DG into Database *****************************"); + List errors = new ArrayList(); + if(this.store != null){ + File xmlDir = new File(xmlPath); + if(xmlDir != null && xmlDir.isDirectory()){ + String[] extensions = new String[] { "xml", "XML" }; + List files = (List) FileUtils.listFiles(xmlDir, extensions, true); + for (File file : files) { + logger.info("Loading DG XML file :" + file.getCanonicalPath()); + try{ + SvcLogicParser.load(file.getCanonicalPath(), this.store); + }catch (Exception e) { + errors.add("Failed to load XML "+file.getCanonicalPath() + ", Exception : "+e.getMessage()); + } + } + }else{ + throw new Exception(xmlPath + " is not a valid XML Directory"); + } + }else{ + throw new Exception("Failed to initialise SvcLogicStore"); + } + + if(errors.size() > 0){ + throw new Exception(errors.toString()); + } + } catch (Exception e) { + logger.error(e.getMessage()); + } + } + + public void activateDg(String activateFilePath) throws Exception { + logger.info("******************** Activating DG into Database *****************************"); + try { + List errors = new ArrayList(); + if(this.store != null){ + File activateFile = new File(activateFilePath); + if(activateFile != null && activateFile.isFile()){ + List fileLines = FileUtils.readLines(activateFile,STRING_ENCODING); + if(fileLines != null ){ + for (String line : fileLines) { + if(line != null && ! line.trim().startsWith("#")){ + String lineArray[] = line.trim().split(":"); + try { + if(lineArray != null && lineArray.length >= 4){ + String module = lineArray[0]; + String rpc = lineArray[1]; + String version = lineArray[2]; + String mode = lineArray[3]; + if(StringUtils.isNotBlank(module) && StringUtils.isNotBlank(rpc) + && StringUtils.isNotBlank(version) && StringUtils.isNotBlank(mode)){ + logger.info("Activating DG :" + line); + SvcLogicGraph graph = this.store.fetch(module, rpc, version, mode); + if(graph != null){ + logger.info("Found Graph :" + line + " Activating ..."); + this.store.activate(graph); + }else{ + throw new Exception("Failed to fetch from Database"); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + errors.add("Failed to Activate "+line + ", "+e.getMessage()); + } + } + } + } + }else{ + throw new Exception(activateFile + " is not a valid Activate file Path"); + } + }else{ + throw new Exception("Failed to initialise SvcLogicStore"); + } + + if(errors.size() > 0){ + throw new Exception(errors.toString()); + } + } catch (Exception e) { + logger.error(e.getMessage()); + } + } + + + public static void main(String[] args) { + try { + String xmlPath = null; + String propertyPath = null; + String activateFile = null; + + if(args != null && args.length >= 3){ + xmlPath = args[0]; + activateFile = args[1]; + propertyPath = args[2]; + }else{ + throw new Exception("Sufficient inputs for DGXMLLoadNActivate are missing "); + } + + //propertyPath = "/Users/bs2796/0Source/ecomp/bvc-3.2.2/others/properties/dblib.properties"; + //xmlPath = DGXMLLoadNActivate.class.getClassLoader().getResource(".").getPath() +"/xml" ; + + DGXMLLoadNActivate dgXMLLoadDB = new DGXMLLoadNActivate(propertyPath); + dgXMLLoadDB.loadDGXMLDir(xmlPath); + dgXMLLoadDB.activateDg(activateFile); + } catch (Exception e) { + e.printStackTrace(); + }finally { + System.exit(1); + } + } } diff --git a/appc-directed-graph/dg-loader/provider/src/main/resources/scripts/dg_load_activate.sh b/appc-directed-graph/dg-loader/provider/src/main/resources/scripts/dg_load_activate.sh index 7d34a45f9..e92efce90 100644 --- a/appc-directed-graph/dg-loader/provider/src/main/resources/scripts/dg_load_activate.sh +++ b/appc-directed-graph/dg-loader/provider/src/main/resources/scripts/dg_load_activate.sh @@ -20,6 +20,7 @@ # ============LICENSE_END========================================================= ### + export BVC_DIR=/opt/app/bvc export DG_DIR=${BVC_DIR}/dg diff --git a/appc-directed-graph/pom.xml b/appc-directed-graph/pom.xml index d4a43ca0d..5779ee486 100644 --- a/appc-directed-graph/pom.xml +++ b/appc-directed-graph/pom.xml @@ -1,6 +1,31 @@ + + 4.0.0 + org.openecomp.appc appc @@ -21,11 +46,11 @@ 1.3.7 3.2.1 2.5 - 1.1.0 1.1.0 1.1.0 1.1.0 + ${project.parent.basedir} @@ -84,7 +109,6 @@ provided - -- 2.16.6