basicAuth.username=admin
basicAuth.password=OBF:1u2a1toa1w8v1tok1u30
-openstack.identity.url = http://10.69.36.11:5000/v3/auth/tokens
-openstack.identity.user = ralph
-openstack.identity.password = OBF:1w951ugg1vun1uha1w8l
+openstack.identity.url = http://10.69.100.11:5000/v3/auth/tokens
+openstack.identity.user = jbalasub
+openstack.identity.password = OBF:1thj1vn01v1p1toq1to41v2p1vo21th3
openstack.types = vserver, l3-network
-openstack.type.vserver.url = http://10.69.36.11:8774/v2.1/servers/{0}
-openstack.type.l3-network.url = http://10.69.36.11:9696/v2.0/networks/{0}
+openstack.type.vserver.url = http://10.69.100.11:8774/v2.1/servers/{0}
+openstack.type.l3-network.url = http://10.69.100.11:9696/v2.0/networks/{0}
openstack.api.microversion = 2.42
"operation": "shift",
"spec": {
"network": {
- "id": "l3-network.id",
- "name": "l3-network.name",
- "admin_state_up": "l3-network.AdminState",
- "shared": "l3-network.sharedNetwork",
- "status": "l3-network.status",
- "subnets": "l3-network.subnets",
- "tenant_id": "l3-network.tenantId"
+ "id": "id",
+ "name": "name",
+ "admin_state_up": "tempList[].adminState",
+ "shared": "tempList[].sharedNetwork",
+ "status": "tempList[].status",
+ "subnets" : {
+ "*": "tempList[].subnets"
+ },
+ "tenant_id" : "tempList[].tenantId"
}
}
},
{
- "operation": "default",
+ "operation": "shift",
"spec": {
+ "tempList": {
+ "*": {
+ "*" : {
+ "$": "attributeList[#3].name",
+ "@": "attributeList[#3].value"
+ },
+ "#ok": "attributeList[#2].dataQuality.status"
+ }
+ },
"*": {
- "host-status": "UNKNOWN"
- }
- }
- }
+ "@" : "&"
+ },
+ "#l3-network": "type",
+ "#ok": "dataQuality.status"
+ }
+ }
-]
+]
\ No newline at end of file
"operation": "shift",
"spec": {
"server": {
- "id": "vserver.id",
- "name": "vserver.name",
- "locked": "vserver.inMaintenance",
- "OS-EXT-SRV-ATTR:hostname": "vserver.hostname",
+ "id": "id",
+ "name": "name",
+ "locked": "tempList[].inMaintenance",
+ "OS-EXT-SRV-ATTR:hostname": "tempList[].hostname",
"image": {
- "id": "vserver.imageId"
- },
-
- "status": "vserver.status",
- "OS-EXT-STS:vm_state": "vserver.vmState",
- "tenant_id": "vserver.tenantId",
- "hostId": "vserver.hostId",
- "OS-EXT-SRV-ATTR:host": "vserver.host",
- "host_status": "vserver.hostStatus"
+ "id": "tempList[].imageId"
+ },
+ "status": "tempList[].status",
+ "OS-EXT-STS:vm_state" : "tempList[].vmState",
+ "user_id" : "tempList[].userId",
+ "tenant_id" : "tempList[].tenantId",
+ "hostId" : "tempList[].hostId",
+ "OS-EXT-SRV-ATTR:host" : "tempList[].host",
+ "host_status" : "tempList[].hostStatus"
}
}
- },
+ }
+ ,
{
- "operation": "default",
+ "operation": "shift",
"spec": {
+ "tempList": {
+ "*": {
+ "*" : {
+ "$": "attributeList[#3].name",
+ "@": "attributeList[#3].value"
+ },
+ "#ok": "attributeList[#2].dataQuality.status"
+ }
+ },
"*": {
- "hostStatus": "UNKNOWN"
- }
- }
- }
+ "@" : "&"
+ },
+ "#vserver": "type",
+ "#ok": "dataQuality.status"
+ }
+ }
]
*/
package org.onap.sdnc.apps.pomba.networkdiscovery.service;
+import com.google.gson.Gson;
+
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import org.onap.logging.ref.slf4j.ONAPLogAdapter;
import org.onap.pomba.common.datatypes.DataQuality;
import org.onap.sdnc.apps.pomba.networkdiscovery.ApplicationException;
-import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Attribute;
import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.NetworkDiscoveryNotification;
import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.NetworkDiscoveryResponse;
import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Resource;
MessageFormat format = new MessageFormat(openstackURL);
for (String resourceId : resourceIds) {
- String url = format.format(new Object[] { resourceId });
- Resource resource = new Resource();
- resource.setType(resourceType);
- resource.setId(resourceId);
- resources.add(resource);
-
+ String url = format.format(new Object[] { resourceId });
Response result;
try {
result = openstackClient.target(url).request().header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON)
if (result.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
String transformedOutput = TransformationUtil.transform(jsonResult, resourceType);
-
log.debug("Jolt transformed output: {}", transformedOutput);
-
- resource.setDataQuality(DataQuality.ok());
- List<Attribute> attributeList = TransformationUtil.toAttributeList(transformedOutput);
- resource.setAttributeList(attributeList);
+
+ Gson gson = new Gson();
+ Resource resourceInst = gson.fromJson(transformedOutput, Resource.class);
+ resources.add(resourceInst);
} else {
+ Resource resource = new Resource();
+ resource.setType(resourceType);
+ resource.setId(resourceId);
resource.setDataQuality(DataQuality.error(jsonResult));
+ resources.add(resource);
}
}
\r
import com.bazaarvoice.jolt.Chainr;\r
import com.bazaarvoice.jolt.JsonUtils;\r
-import com.google.gson.JsonElement;\r
-import com.google.gson.JsonParser;\r
\r
import java.io.File;\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
import java.util.List;\r
-import java.util.Map.Entry;\r
-import java.util.Set;\r
-\r
-import org.onap.pomba.common.datatypes.DataQuality;\r
-import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Attribute;\r
\r
public class TransformationUtil {\r
\r
private static final String CONFIG_JOLT = "config/jolt";\r
- private static final String EMPTY_STRING = "";\r
\r
private TransformationUtil() {\r
throw new IllegalStateException("Utility class");\r
return JsonUtils.toJsonString(output);\r
}\r
\r
- /**\r
- * Converts the second level of JsonElements from the given json to a list of\r
- * Network Discovery Attributes.\r
- * \r
- * @param json\r
- * @return\r
- */\r
- public static List<Attribute> toAttributeList(String json) {\r
-\r
- JsonParser parser = new JsonParser();\r
- JsonElement elem = parser.parse(json);\r
-\r
- Set<Entry<String, JsonElement>> entrySet = elem.getAsJsonObject().entrySet();\r
-\r
- List<Attribute> result = new ArrayList<>();\r
-\r
- Iterator<Entry<String, JsonElement>> iter = entrySet.iterator();\r
- while (iter.hasNext()) {\r
- Entry<String, JsonElement> next = iter.next();\r
-\r
- JsonElement vserverElem = next.getValue();\r
- Set<Entry<String, JsonElement>> vserverEntrySet = vserverElem.getAsJsonObject().entrySet();\r
- Iterator<Entry<String, JsonElement>> vserverIter = vserverEntrySet.iterator();\r
- while (vserverIter.hasNext()) {\r
- Entry<String, JsonElement> vserverNext = vserverIter.next();\r
- Attribute attr = new Attribute();\r
- attr.setName(vserverNext.getKey());\r
- if (vserverNext.getValue().isJsonNull()) {\r
- attr.setValue(EMPTY_STRING);\r
- } else {\r
- attr.setValue(vserverNext.getValue().getAsString());\r
- }\r
- attr.setDataQuality(DataQuality.ok());\r
- result.add(attr);\r
- }\r
- }\r
- return result;\r
- }\r
-\r
}
\ No newline at end of file
@Test
public void testDiscoverVserver() throws Exception {
- String vserverId = UUID.randomUUID().toString();
+ String vserverId = "2c311eae-f542-4173-8a01-582922abd495";
String resourcePath = MessageFormat.format("/v2.1/servers/{0}",
new Object[] { vserverId });
\r
package org.onap.sdnc.apps.pomba.networkdiscovery.unittest.service.util;\r
\r
-import static org.junit.Assert.assertThat;\r
-\r
import com.bazaarvoice.jolt.JsonUtils;\r
import com.bazaarvoice.jolt.exception.JsonUnmarshalException;\r
+import com.google.gson.Gson;\r
\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.hamcrest.CoreMatchers;\r
import org.junit.Assert;\r
import org.junit.Rule;\r
import org.junit.Test;\r
import org.junit.rules.ExpectedException;\r
-import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Attribute;\r
+import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Resource;\r
import org.onap.sdnc.apps.pomba.networkdiscovery.service.util.TransformationUtil;\r
\r
public class TransformationUtilTest {\r
\r
String resultJson = TransformationUtil.transform(JsonUtils.toJsonString(sourceObject), "vserver");\r
\r
+ Gson gson = new Gson();\r
+ Resource resourceInst = gson.fromJson(resultJson, Resource.class);\r
+ String resourceInstJson = gson.toJson(resourceInst);\r
+\r
Object expectedObject = JsonUtils.filepathToObject(TEST_RESOURCES + "vserver-expected.json");\r
\r
Assert.assertEquals("Json transformation result does not match expected content",\r
JsonUtils.toPrettyJsonString(expectedObject),\r
- JsonUtils.toPrettyJsonString(JsonUtils.jsonToObject(resultJson)));\r
+ JsonUtils.toPrettyJsonString(JsonUtils.jsonToObject(resourceInstJson)));\r
\r
}\r
\r
Object sourceObject = JsonUtils.filepathToObject(TEST_RESOURCES + "l3network-input.json");\r
String resultJson = TransformationUtil.transform(JsonUtils.toJsonString(sourceObject), "l3-network");\r
\r
+ Gson gson = new Gson();\r
+ Resource resourceInst = gson.fromJson(resultJson, Resource.class);\r
+ String resourceInstJson = gson.toJson(resourceInst);\r
+\r
Object expectedObject = JsonUtils.filepathToObject(TEST_RESOURCES + "l3network-expected.json");\r
\r
Assert.assertEquals("Json transformation result does not match expected content",\r
JsonUtils.toPrettyJsonString(expectedObject),\r
- JsonUtils.toPrettyJsonString(JsonUtils.jsonToObject(resultJson)));\r
+ JsonUtils.toPrettyJsonString(JsonUtils.jsonToObject(resourceInstJson)));\r
\r
}\r
\r
TransformationUtil.transform("xxx", "foobar");\r
}\r
\r
- @Test\r
- public void testToAttributeList() {\r
- Map<String, String> expectedAttributes = new HashMap<String, String>();\r
- expectedAttributes.put("name", "norm_bouygues");\r
- expectedAttributes.put("hostId", "ea1660efbbedda164379afacdc622305c4b88cebfb84119472d286a8");\r
- expectedAttributes.put("hostStatus", "UP");\r
- expectedAttributes.put("id", "2c311eae-f542-4173-8a01-582922abd495");\r
- expectedAttributes.put("status", "ACTIVE");\r
- expectedAttributes.put("vmState", "active");\r
- expectedAttributes.put("hostname", "norm-bouygues");\r
- expectedAttributes.put("inMaintenance", "true");\r
- expectedAttributes.put("imageId", "c0022890-d91f-422c-91c5-3866edeae768");\r
- expectedAttributes.put("tenantId", "15ad36d394e744838e947ca90609f805");\r
- expectedAttributes.put("host", "Setup-NCSO-OTT-E-C2");\r
-\r
- Object inputJson = JsonUtils.filepathToObject(TEST_RESOURCES + "vserver-expected.json");\r
- List<Attribute> resultAttributeList = TransformationUtil.toAttributeList(JsonUtils.toJsonString(inputJson));\r
-\r
- Map<String, String> resultAttributes = new HashMap<>();\r
-\r
- for (Attribute attribute : resultAttributeList) {\r
- resultAttributes.put(attribute.getName(), attribute.getValue());\r
- }\r
- assertThat(expectedAttributes, CoreMatchers.is(resultAttributes));\r
- }\r
-\r
- @Test\r
- public void testToAttributeListNullJsonValue() {\r
- Map<String, String> expectedAttributes = new HashMap<String, String>();\r
- expectedAttributes.put("name", "");\r
-\r
- String inputJson = "{\"server\": { \"name\": null }}";\r
-\r
- List<Attribute> resultAttributeList = TransformationUtil.toAttributeList(inputJson);\r
-\r
- Map<String, String> resultAttributes = new HashMap<>();\r
-\r
- for (Attribute attribute : resultAttributeList) {\r
- resultAttributes.put(attribute.getName(), attribute.getValue());\r
- }\r
- assertThat(expectedAttributes, CoreMatchers.is(resultAttributes));\r
- }\r
-\r
}\r
{\r
- "l3-network": {\r
- "id": "8df84f0a-737a-4628-be9c-c3c78454f9d9",\r
- "name": "NET_503",\r
- "AdminState": true,\r
- "sharedNetwork": true,\r
- "status": "ACTIVE",\r
- "subnets": [\r
- "d0e6ecad-7bc9-4138-b9e8-e742bdf9afd5"\r
- ],\r
- "tenantId": "c44b872f6830498b88c4989d67b2a6b7",\r
- "host-status": "UNKNOWN"\r
- }\r
-}\r
+ "id" : "8df84f0a-737a-4628-be9c-c3c78454f9d9",\r
+ "name" : "NET_503",\r
+ "type" : "l3-network",\r
+ "dataQuality" : {\r
+ "status" : "ok"\r
+ },\r
+ "attributeList" : [ {\r
+ "name" : "adminState",\r
+ "value" : "true",\r
+ "dataQuality" : {\r
+ "status" : "ok"\r
+ }\r
+ }, {\r
+ "name" : "sharedNetwork",\r
+ "value" : "true",\r
+ "dataQuality" : {\r
+ "status" : "ok"\r
+ }\r
+ }, {\r
+ "name" : "status",\r
+ "value" : "ACTIVE",\r
+ "dataQuality" : {\r
+ "status" : "ok"\r
+ }\r
+ }, {\r
+ "name" : "subnets",\r
+ "value" : "d0e6ecad-7bc9-4138-b9e8-e742bdf9afd5",\r
+ "dataQuality" : {\r
+ "status" : "ok"\r
+ }\r
+ }, {\r
+ "name" : "tenantId",\r
+ "value" : "c44b872f6830498b88c4989d67b2a6b7",\r
+ "dataQuality" : {\r
+ "status" : "ok"\r
+ }\r
+ } ]\r
+}
\ No newline at end of file
{\r
- "vserver" : {\r
- "id" : "2c311eae-f542-4173-8a01-582922abd495",\r
- "name" : "norm_bouygues",\r
- "inMaintenance" : true,\r
- "hostname" : "norm-bouygues",\r
- "imageId" : "c0022890-d91f-422c-91c5-3866edeae768",\r
- "status" : "ACTIVE",\r
- "vmState" : "active",\r
- "tenantId" : "15ad36d394e744838e947ca90609f805",\r
- "hostId" : "ea1660efbbedda164379afacdc622305c4b88cebfb84119472d286a8",\r
- "host" : "Setup-NCSO-OTT-E-C2",\r
- "hostStatus" : "UP"\r
- }\r
+ "id" : "2c311eae-f542-4173-8a01-582922abd495",\r
+ "name" : "norm_bouygues",\r
+ "type" : "vserver",\r
+ "dataQuality" : {\r
+ "status" : "ok"\r
+ },\r
+ "attributeList" : [ {\r
+ "name" : "inMaintenance",\r
+ "value" : "true",\r
+ "dataQuality" : {\r
+ "status" : "ok"\r
+ }\r
+ }, {\r
+ "name" : "hostname",\r
+ "value" : "norm-bouygues",\r
+ "dataQuality" : {\r
+ "status" : "ok"\r
+ }\r
+ }, {\r
+ "name" : "imageId",\r
+ "value" : "c0022890-d91f-422c-91c5-3866edeae768",\r
+ "dataQuality" : {\r
+ "status" : "ok"\r
+ }\r
+ }, {\r
+ "name" : "status",\r
+ "value" : "ACTIVE",\r
+ "dataQuality" : {\r
+ "status" : "ok"\r
+ }\r
+ }, {\r
+ "name" : "vmState",\r
+ "value" : "active",\r
+ "dataQuality" : {\r
+ "status" : "ok"\r
+ }\r
+ }, {\r
+ "name" : "userId",\r
+ "value" : "bdaf4fcde1574450bfa488b3221033d8",\r
+ "dataQuality" : {\r
+ "status" : "ok"\r
+ }\r
+ }, {\r
+ "name" : "tenantId",\r
+ "value" : "15ad36d394e744838e947ca90609f805",\r
+ "dataQuality" : {\r
+ "status" : "ok"\r
+ }\r
+ }, {\r
+ "name" : "hostId",\r
+ "value" : "ea1660efbbedda164379afacdc622305c4b88cebfb84119472d286a8",\r
+ "dataQuality" : {\r
+ "status" : "ok"\r
+ }\r
+ }, {\r
+ "name" : "host",\r
+ "value" : "Setup-NCSO-OTT-E-C2",\r
+ "dataQuality" : {\r
+ "status" : "ok"\r
+ }\r
+ }, {\r
+ "name" : "hostStatus",\r
+ "value" : "UP",\r
+ "dataQuality" : {\r
+ "status" : "ok"\r
+ }\r
+ } ]\r
}
\ No newline at end of file