diff options
12 files changed, 227 insertions, 262 deletions
diff --git a/features/ccsdk-sli-adaptors-all/pom.xml b/features/ccsdk-sli-adaptors-all/pom.xml index 68ad0f776..1e3ba8ada 100644 --- a/features/ccsdk-sli-adaptors-all/pom.xml +++ b/features/ccsdk-sli-adaptors-all/pom.xml @@ -44,6 +44,7 @@ <type>xml</type> <classifier>features</classifier> </dependency> + --> <dependency> <groupId>${project.groupId}</groupId> <artifactId>ccsdk-grpc-client</artifactId> @@ -51,7 +52,6 @@ <type>xml</type> <classifier>features</classifier> </dependency> - --> <dependency> <groupId>${project.groupId}</groupId> <artifactId>ccsdk-netbox-client</artifactId> diff --git a/grpc-resource/provider/pom.xml b/grpc-resource/provider/pom.xml index 9c0a4a0d9..c567bba13 100644 --- a/grpc-resource/provider/pom.xml +++ b/grpc-resource/provider/pom.xml @@ -106,6 +106,12 @@ <version>${grpc.version}</version> </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + <scope>provided</scope> + </dependency> + <!-- Testing --> <dependency> <groupId>junit</groupId> diff --git a/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/GrpcProperties.java b/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/GrpcProperties.java index fef1a5963..96775f379 100644 --- a/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/GrpcProperties.java +++ b/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/GrpcProperties.java @@ -15,100 +15,62 @@ */ package org.onap.ccsdk.sli.adaptors.grpc; -import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.util.HashSet; -import java.util.Optional; +import java.io.InputStream; +import java.net.URL; import java.util.Properties; -import java.util.Set; -import org.onap.ccsdk.sli.core.utils.JREFileResolver; -import org.onap.ccsdk.sli.core.utils.KarafRootFileResolver; -import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver; -import org.onap.ccsdk.sli.core.utils.common.BundleContextFileResolver; -import org.onap.ccsdk.sli.core.utils.common.SdncConfigEnvVarFileResolver; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * Responsible for determining the properties file to use. - * - * <ol> - * <li>A directory identified by the system environment variable <code>SDNC_CONFIG_DIR</code></li> - * <li>A directory identified by the JRE argument <code>grpc.properties</code></li> - * <li>A <code>grpc.properties</code> file located in the karaf root directory</li> - * </ol> - * - * Partial copy and adaptation of org.onap.ccsdk.sli.adaptors.aai.AAIServiceProvider - */ public class GrpcProperties { private static final Logger LOG = LoggerFactory.getLogger(GrpcProperties.class); private static final String GRPC_PROPERTY_FILE_NAME = "grpc.properties"; - private static final String MISSING_PROPERTY_FILE = - "Missing configuration properties resource for GRPC: " + GRPC_PROPERTY_FILE_NAME; + private static final String DEFAULT_PROPERTIES_DIR = "/opt/onap/ccsdk/data/properties"; + private static final String PROPERTIES_DIR_KEY = "SDNC_CONFIG_DIR"; + private static final String BLUEPRINT_PROCESSOR_URL_PROP = "org.onap.ccsdk.sli.adaptors.grpc.blueprint.processor.url"; private static final String BLUEPRINT_PROCESSOR_PORT_PROP = "org.onap.ccsdk.sli.adaptors.grpc.blueprint.processor.port"; - private Set<PropertiesFileResolver> fileResolvers = new HashSet<>(); private Properties properties; public GrpcProperties() { - fileResolvers.add(new SdncConfigEnvVarFileResolver("Using property file (1) from environment variable")); - fileResolvers.add(new BundleContextFileResolver("Using property file (2) from BundleContext property", - GrpcProperties.class)); - fileResolvers.add(new JREFileResolver("Using property file (3) from JRE argument", GrpcProperties.class)); - fileResolvers.add(new KarafRootFileResolver("Using property file (4) from karaf root", this)); - loadProps(); } public String getUrl() { - checkArgument(properties != null); return properties.getProperty(BLUEPRINT_PROCESSOR_URL_PROP); } public int getPort() { - checkArgument(properties != null); return Integer.parseInt(properties.getProperty(BLUEPRINT_PROCESSOR_PORT_PROP)); } - private void checkArgument(final boolean argument) { - if (!argument) { - LOG.info("Propety file {} was missing, trying to reload it", GRPC_PROPERTY_FILE_NAME); - loadProps(); - if (properties == null) { - throw new IllegalArgumentException(MISSING_PROPERTY_FILE); - } - } - } - private void loadProps() { - // determines properties file as according to the priority described in the class header comment - final File propertiesFile = determinePropertiesFile(); - if (propertiesFile != null) { - try (FileInputStream fileInputStream = new FileInputStream(propertiesFile)) { - properties = new Properties(); - properties.load(fileInputStream); - } catch (final IOException e) { - String errorMsg = "Failed to load properties for file: " + propertiesFile.toString(); - LOG.error(errorMsg, errorMsg); - } - } - } + properties = new Properties(); + // Try to load config from dir + final String ccsdkConfigDir = + System.getProperty(PROPERTIES_DIR_KEY, DEFAULT_PROPERTIES_DIR) + "/" + GRPC_PROPERTY_FILE_NAME; + try (FileInputStream in = new FileInputStream(ccsdkConfigDir)) { + properties.load(in); + LOG.info("Loaded {} properties from file {}", properties.size(), ccsdkConfigDir); + } catch (Exception e) { + // Try to load config from jar + final Bundle bundle = FrameworkUtil.getBundle(GrpcProperties.class); + final BundleContext ctx = bundle.getBundleContext(); + final URL url = ctx.getBundle().getResource(GRPC_PROPERTY_FILE_NAME); - private File determinePropertiesFile() { - for (final PropertiesFileResolver resolver : fileResolvers) { - final Optional<File> fileOptional = resolver.resolveFile(GRPC_PROPERTY_FILE_NAME); - if (fileOptional.isPresent()) { - final File file = fileOptional.get(); - LOG.info("{} {}", resolver.getSuccessfulResolutionMessage(), file.getPath()); - return file; + try (InputStream inputStream = url.openStream()) { + properties.load(inputStream); + LOG.info("Loaded {} properties from file {}", properties.size(), GRPC_PROPERTY_FILE_NAME); + } catch (IOException e1) { + LOG.error("Failed to load properties for file: {} " + GRPC_PROPERTY_FILE_NAME, e1); } } - - LOG.error(MISSING_PROPERTY_FILE); - return null; } } diff --git a/grpc-resource/provider/src/main/resources/grpc.properties b/grpc-resource/provider/src/main/resources/grpc.properties index 2d4e795e6..650910eb9 100755..100644 --- a/grpc-resource/provider/src/main/resources/grpc.properties +++ b/grpc-resource/provider/src/main/resources/grpc.properties @@ -1,4 +1,5 @@ -# Copyright (C) 2019 Bell Canada +# +# Copyright (C) 2019 Bell Canada. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,5 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +# org.onap.ccsdk.sli.adaptors.grpc.blueprint.processor.url=blueprint-processor -org.onap.ccsdk.sli.adaptors.grpc.blueprint.processor.port=9111
\ No newline at end of file +org.onap.ccsdk.sli.adaptors.grpc.blueprint.processor.port=9111 diff --git a/netbox-client/provider/pom.xml b/netbox-client/provider/pom.xml index 3af22edb2..f7e8ccf92 100644 --- a/netbox-client/provider/pom.xml +++ b/netbox-client/provider/pom.xml @@ -79,6 +79,11 @@ <version>${project.version}</version> <scope>compile</scope> </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + <scope>provided</scope> + </dependency> <!--Testing--> <dependency> @@ -111,11 +116,6 @@ <version>1.2.3</version> <scope>test</scope> </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.core</artifactId> - <scope>test</scope> - </dependency> </dependencies> <build> diff --git a/netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/property/NetboxProperties.java b/netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/property/NetboxProperties.java index ee493ec18..2eecf6e3a 100644 --- a/netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/property/NetboxProperties.java +++ b/netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/property/NetboxProperties.java @@ -15,102 +15,62 @@ */ package org.onap.ccsdk.sli.adaptors.netbox.property; -import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.util.HashSet; -import java.util.Optional; +import java.io.InputStream; +import java.net.URL; import java.util.Properties; -import java.util.Set; - -import org.onap.ccsdk.sli.adaptors.netbox.api.IpamException; -import org.onap.ccsdk.sli.core.utils.JREFileResolver; -import org.onap.ccsdk.sli.core.utils.KarafRootFileResolver; -import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver; -import org.onap.ccsdk.sli.core.utils.common.BundleContextFileResolver; -import org.onap.ccsdk.sli.core.utils.common.SdncConfigEnvVarFileResolver; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * Responsible for determining the properties file to use. - * - * <ol> - * <li>A directory identified by the system environment variable <code>SDNC_CONFIG_DIR</code></li> - * <li>A directory identified by the JRE argument <code>netbox.properties</code></li> - * <li>A <code>netbox.properties</code> file located in the karaf root directory</li> - * </ol> - * - * Partial copy and adaptation of org.onap.ccsdk.sli.adaptors.aai.AAIServiceProvider - */ public class NetboxProperties { private static final Logger LOG = LoggerFactory.getLogger(NetboxProperties.class); private static final String NETBOX_PROPERTY_FILE_NAME = "netbox.properties"; - private static final String MISSING_PROPERTY_FILE = - "Missing configuration properties resource for Netbox: " + NETBOX_PROPERTY_FILE_NAME; + private static final String DEFAULT_PROPERTIES_DIR = "/opt/onap/ccsdk/data/properties"; + private static final String PROPERTIES_DIR_KEY = "SDNC_CONFIG_DIR"; + private static final String NETBOX_URL_PROP = "org.onap.ccsdk.sli.adaptors.netbox.url"; private static final String NETBOX_API_KEY_PROP = "org.onap.ccsdk.sli.adaptors.netbox.apikey"; - private Set<PropertiesFileResolver> fileResolvers = new HashSet<>(); private Properties properties; public NetboxProperties() { - fileResolvers.add(new SdncConfigEnvVarFileResolver("Using property file (1) from environment variable")); - fileResolvers.add(new BundleContextFileResolver("Using property file (2) from BundleContext property", - NetboxProperties.class)); - fileResolvers.add(new JREFileResolver("Using property file (3) from JRE argument", NetboxProperties.class)); - fileResolvers.add(new KarafRootFileResolver("Using property file (4) from karaf root", this)); - loadProps(); } public String getHost() { - checkArgument(properties != null); return properties.getProperty(NETBOX_URL_PROP); } public String getApiKey() { - checkArgument(properties != null); return properties.getProperty(NETBOX_API_KEY_PROP); } - private void checkArgument(final boolean argument) { - if (!argument) { - LOG.info("Propety file {} was missing, trying to reload it", NETBOX_PROPERTY_FILE_NAME); - loadProps(); - if (properties == null) { - throw new IllegalArgumentException(MISSING_PROPERTY_FILE); - } - } - } - private void loadProps() { - // determines properties file as according to the priority described in the class header comment - final File propertiesFile = determinePropertiesFile(); - if (propertiesFile != null) { - try (FileInputStream fileInputStream = new FileInputStream(propertiesFile)) { - properties = new Properties(); - properties.load(fileInputStream); - } catch (final IOException e) { - String errorMsg = "Failed to load properties for file: " + propertiesFile.toString(); - LOG.error(errorMsg, new IpamException(errorMsg)); - } - } - } + properties = new Properties(); + // Try to load config from dir + final String ccsdkConfigDir = + System.getProperty(PROPERTIES_DIR_KEY, DEFAULT_PROPERTIES_DIR) + "/" + NETBOX_PROPERTY_FILE_NAME; + try (FileInputStream in = new FileInputStream(ccsdkConfigDir)) { + properties.load(in); + LOG.info("Loaded {} properties from file {}", properties.size(), ccsdkConfigDir); + } catch (Exception e) { + // Try to load config from jar + final Bundle bundle = FrameworkUtil.getBundle(NetboxProperties.class); + final BundleContext ctx = bundle.getBundleContext(); + final URL url = ctx.getBundle().getResource(NETBOX_PROPERTY_FILE_NAME); - private File determinePropertiesFile() { - for (final PropertiesFileResolver resolver : fileResolvers) { - final Optional<File> fileOptional = resolver.resolveFile(NETBOX_PROPERTY_FILE_NAME); - if (fileOptional.isPresent()) { - final File file = fileOptional.get(); - LOG.info("{} {}", resolver.getSuccessfulResolutionMessage(), file.getPath()); - return file; + try (InputStream inputStream = url.openStream()) { + properties.load(inputStream); + LOG.info("Loaded {} properties from file {}", properties.size(), NETBOX_PROPERTY_FILE_NAME); + } catch (IOException e1) { + LOG.error("Failed to load properties for file: {} " + NETBOX_PROPERTY_FILE_NAME, e1); } } - - LOG.error(MISSING_PROPERTY_FILE, new IpamException(MISSING_PROPERTY_FILE)); - return null; } } diff --git a/netbox-client/provider/src/test/java/org/onap/ccsdk/sli/adaptors/netbox/property/NetboxPropertiesTest.java b/netbox-client/provider/src/test/java/org/onap/ccsdk/sli/adaptors/netbox/property/NetboxPropertiesTest.java deleted file mode 100644 index be5aabfc2..000000000 --- a/netbox-client/provider/src/test/java/org/onap/ccsdk/sli/adaptors/netbox/property/NetboxPropertiesTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2018 Bell Canada. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.ccsdk.sli.adaptors.netbox.property; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.Appender; -import java.util.List; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.slf4j.LoggerFactory; - -@RunWith(MockitoJUnitRunner.class) -public class NetboxPropertiesTest { - - private NetboxProperties props; - - @Mock - private Appender<ILoggingEvent> appender; - @Captor - private ArgumentCaptor<ILoggingEvent> captor; - - @Before - public void setup() { - ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory - .getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); - logger.addAppender(appender); - } - - @Test - public void testMissingFile() { - props = new NetboxProperties(); - - verifyLogEntry( - "Missing configuration properties resource for Netbox: netbox.properties"); - } - - private void verifyLogEntry(String message) { - verify(appender, times(1)).doAppend(captor.capture()); - List<ILoggingEvent> allValues = captor.getAllValues(); - for (ILoggingEvent loggingEvent : allValues) { - Assert.assertTrue(loggingEvent.getFormattedMessage().contains(message)); - } - } -}
\ No newline at end of file diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java index 944429a3c..c51b03846 100644 --- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java +++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import org.onap.ccsdk.sli.adaptors.ra.comp.AllocationData; import org.onap.ccsdk.sli.adaptors.ra.comp.EndPointAllocator; import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceData; import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceEntity; @@ -124,7 +125,9 @@ public class ResourceAllocator implements SvcLogicResource { } else if (resourceTargetId != null && resourceTargetType != null && resourceName != null) { ResourceData rd = endPointAllocator.getResource(resourceTargetType, resourceTargetId, resourceName, resourceEntityTypeFilter, resourceEntityIdFilter, resourceShareGroupFilter); - setResourceDataInContext(ctx, prefix, Collections.singletonList(rd)); + if (rd != null) { + setResourceDataInContext(ctx, prefix, Collections.singletonList(rd)); + } } else if ((resourceTargetTypeFilter != null || resourceTargetIdFilter != null) && resourceName != null) { List<ResourceData> rdlist = endPointAllocator.getResourcesForTarget(resourceTargetTypeFilter, resourceTargetIdFilter, resourceName); @@ -157,6 +160,10 @@ public class ResourceAllocator implements SvcLogicResource { } private void setResourceDataInContext(SvcLogicContext ctx, String prefix, List<ResourceData> rdlist) { + if (rdlist == null || rdlist.isEmpty()) { + return; + } + prefix = prefix == null ? "" : prefix + '.'; setAttr(ctx, prefix + "resource-list_length", String.valueOf(rdlist.size())); @@ -170,7 +177,6 @@ public class ResourceAllocator implements SvcLogicResource { setAttr(ctx, pp + "endpoint-position", rd.endPointPosition); setAttr(ctx, pp + "resource-target-type", rd.resourceTargetType); setAttr(ctx, pp + "resource-target-id", rd.resourceTargetId); - // SDNGC-7687 setAttr(ctx, pp + "resource-target-value", rd.resourceTargetValue); setAttr(ctx, pp + "status", rd.status); @@ -180,6 +186,28 @@ public class ResourceAllocator implements SvcLogicResource { setAttr(ctx, pp + kk, value); } } + + if (rd.allocationDataList != null && !rd.allocationDataList.isEmpty()) { + + setAttr(ctx, pp + "allocation-data-list_length", String.valueOf(rd.allocationDataList.size())); + + for (int j = 0; j < rd.allocationDataList.size(); j++) { + AllocationData ad = rd.allocationDataList.get(j); + + String ppp = pp + "allocation-data-list[" + j + "]."; + + setAttr(ctx, ppp + "resource-entity-type", ad.resourceEntityType); + setAttr(ctx, ppp + "resource-entity-id", ad.resourceEntityId); + setAttr(ctx, ppp + "resource-entity-version", ad.resourceEntityVersion); + + if (ad.data != null && !ad.data.isEmpty()) { + for (String kk : ad.data.keySet()) { + String value = String.valueOf(ad.data.get(kk)); + setAttr(ctx, ppp + kk, value); + } + } + } + } } } diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/AllocationData.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/AllocationData.java new file mode 100644 index 000000000..3e0e6b140 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/AllocationData.java @@ -0,0 +1,11 @@ +package org.onap.ccsdk.sli.adaptors.ra.comp; + +import java.util.Map; + +public class AllocationData { + + public String resourceEntityType; + public String resourceEntityId; + public String resourceEntityVersion; + public Map<String, String> data; +} diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java index d188429ea..ab73dab1b 100644 --- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java +++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java @@ -224,40 +224,8 @@ public class EndPointAllocatorImpl implements EndPointAllocator { log.info("ResourceName:" + r.resourceKey.resourceName + " assetId:" + r.resourceKey.assetId); - ResourceData rd = new ResourceData(); + ResourceData rd = getResourceData(r); rdlist.add(rd); - - rd.resourceName = r.resourceKey.resourceName; - int i1 = r.resourceKey.assetId.indexOf("::"); - if (i1 > 0) { - rd.resourceTargetType = r.resourceKey.assetId.substring(0, i1); - rd.resourceTargetId = r.resourceKey.assetId.substring(i1 + 2); - - int i2 = r.resourceKey.assetId.lastIndexOf("::"); - if (i2 > i1) { - rd.resourceTargetValue = r.resourceKey.assetId.substring(i2 + 2); - } - } else { - rd.resourceTargetType = ""; - rd.resourceTargetId = r.resourceKey.assetId; - } - - rd.data = new HashMap<>(); - - if (r instanceof RangeResource) { - RangeResource rr = (RangeResource) r; - - log.info("rr.used: " + rr.used); - String ss = String.valueOf(rr.used); - ss = ss.substring(1, ss.length() - 1); - rd.data.put("allocated", ss); - - } else if (r instanceof LimitResource) { - LimitResource lr = (LimitResource) r; - - log.info("lr.used: " + lr.used); - rd.data.put("allocated", String.valueOf(lr.used)); - } } return rdlist; @@ -266,7 +234,6 @@ public class EndPointAllocatorImpl implements EndPointAllocator { @Override public ResourceData getResource(String resourceTargetType, String resourceTargetId, String resourceName, String resourceEntityTypeFilter, String resourceEntityIdFilter, String resourceShareGroupFilter) { - ResourceData rd = new ResourceData(); String assetId = resourceTargetType + "::" + resourceTargetId; String resourceUnionFilter = null; @@ -288,36 +255,87 @@ public class EndPointAllocatorImpl implements EndPointAllocator { if (r != null) { log.info("ResourceName:" + r.resourceKey.resourceName + " assetId:" + r.resourceKey.assetId); - rd.resourceName = r.resourceKey.resourceName; - int i1 = r.resourceKey.assetId.indexOf("::"); - if (i1 > 0) { - rd.resourceTargetType = r.resourceKey.assetId.substring(0, i1); - rd.resourceTargetId = r.resourceKey.assetId.substring(i1 + 2); + ResourceData rd = getResourceData(r); + return rd; + } - int i2 = r.resourceKey.assetId.lastIndexOf("::"); - if (i2 > i1) { - rd.resourceTargetValue = r.resourceKey.assetId.substring(i2 + 2); - } - } else { - rd.resourceTargetType = ""; - rd.resourceTargetId = r.resourceKey.assetId; + return null; + } + + private ResourceData getResourceData(Resource r) { + ResourceData rd = new ResourceData(); + + rd.resourceName = r.resourceKey.resourceName; + int i1 = r.resourceKey.assetId.indexOf("::"); + if (i1 > 0) { + rd.resourceTargetType = r.resourceKey.assetId.substring(0, i1); + rd.resourceTargetId = r.resourceKey.assetId.substring(i1 + 2); + + int i2 = r.resourceKey.assetId.lastIndexOf("::"); + if (i2 > i1) { + rd.resourceTargetValue = r.resourceKey.assetId.substring(i2 + 2); } + } else { + rd.resourceTargetType = ""; + rd.resourceTargetId = r.resourceKey.assetId; + } - rd.data = new HashMap<>(); + rd.data = new HashMap<>(); + + if (r instanceof RangeResource) { + RangeResource rr = (RangeResource) r; + + log.info("rr.used: " + rr.used); + String ss = String.valueOf(rr.used); + ss = ss.substring(1, ss.length() - 1); + rd.data.put("allocated", ss); + + } else if (r instanceof LimitResource) { + LimitResource lr = (LimitResource) r; + + log.info("lr.used: " + lr.used); + rd.data.put("allocated", String.valueOf(lr.used)); + } + + rd.allocationDataList = new ArrayList<>(); + + if (r.allocationItems != null) { + for (AllocationItem ai : r.allocationItems) { + AllocationData ad = new AllocationData(); + rd.allocationDataList.add(ad); + + i1 = ai.resourceUnionId.indexOf("::"); + if (i1 > 0) { + ad.resourceEntityType = ai.resourceUnionId.substring(0, i1); + ad.resourceEntityId = ai.resourceUnionId.substring(i1 + 2); + } else { + ad.resourceEntityType = ""; + ad.resourceEntityId = ai.resourceUnionId; + } - if (r instanceof RangeResource) { - RangeResource rr = (RangeResource) r; + i1 = ai.resourceSetId.lastIndexOf("::"); + if (i1 > 0) { + ad.resourceEntityVersion = ai.resourceSetId.substring(i1 + 2); + } else { + ad.resourceEntityVersion = ""; + } + + ad.data = new HashMap<>(); + + if (ai instanceof RangeAllocationItem) { + RangeAllocationItem rai = (RangeAllocationItem) ai; - log.info("rr.used: " + rr.used); - String ss = String.valueOf(rr.used); - ss = ss.substring(1, ss.length() - 1); - rd.data.put("allocated", ss); + log.info("rr.used: " + rai.used); + String ss = String.valueOf(rai.used); + ss = ss.substring(1, ss.length() - 1); + ad.data.put("allocated", ss); - } else if (r instanceof LimitResource) { - LimitResource lr = (LimitResource) r; + } else if (ai instanceof LimitAllocationItem) { + LimitAllocationItem lai = (LimitAllocationItem) ai; - log.info("lr.used: " + lr.used); - rd.data.put("allocated", String.valueOf(lr.used)); + log.info("lr.used: " + lai.used); + ad.data.put("allocated", String.valueOf(lai.used)); + } } } diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceData.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceData.java index a5881b957..a20c01d79 100644 --- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceData.java +++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceData.java @@ -21,6 +21,7 @@ package org.onap.ccsdk.sli.adaptors.ra.comp; +import java.util.List; import java.util.Map; public class ResourceData { @@ -29,7 +30,8 @@ public class ResourceData { public String resourceTargetId; public String resourceTargetValue; public String resourceTargetType; + public String endPointPosition; public String status; public Map<String, String> data; - public String endPointPosition; + public List<AllocationData> allocationDataList; } diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestQueryResource.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestQueryResource.java index 4be985b2a..f31a3859a 100644 --- a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestQueryResource.java +++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestQueryResource.java @@ -85,6 +85,27 @@ public class TestQueryResource { Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].resource-target-type"), "Port"); Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].resource-target-id"), "TESTPORT-1-2"); Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocated"), "0, 1, 2, 3, 4"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list_length"), "5"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[0].resource-entity-type"), "EVC"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[0].resource-entity-id"), "TEST-0-1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[0].resource-entity-version"), "1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[0].allocated"), "0"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[1].resource-entity-type"), "EVC"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[1].resource-entity-id"), "TEST-1-1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[1].resource-entity-version"), "1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[1].allocated"), "1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[2].resource-entity-type"), "EVC"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[2].resource-entity-id"), "TEST-2-1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[2].resource-entity-version"), "1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[2].allocated"), "2"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[3].resource-entity-type"), "EVC"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[3].resource-entity-id"), "TEST-3-1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[3].resource-entity-version"), "1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[3].allocated"), "3"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[4].resource-entity-type"), "EVC"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[4].resource-entity-id"), "TEST-4-1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[4].resource-entity-version"), "1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[4].allocated"), "4"); } @Test @@ -111,5 +132,26 @@ public class TestQueryResource { Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Port"); Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "TESTPORT-1-1"); Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"), "1500"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list_length"), "5"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[0].resource-entity-type"), "EVC"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[0].resource-entity-id"), "TEST-0-1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[0].resource-entity-version"), "1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[0].allocated"), "100"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[1].resource-entity-type"), "EVC"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[1].resource-entity-id"), "TEST-1-1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[1].resource-entity-version"), "1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[1].allocated"), "200"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[2].resource-entity-type"), "EVC"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[2].resource-entity-id"), "TEST-2-1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[2].resource-entity-version"), "1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[2].allocated"), "300"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[3].resource-entity-type"), "EVC"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[3].resource-entity-id"), "TEST-3-1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[3].resource-entity-version"), "1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[3].allocated"), "400"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[4].resource-entity-type"), "EVC"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[4].resource-entity-id"), "TEST-4-1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[4].resource-entity-version"), "1"); + Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[4].allocated"), "500"); } } |