summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShiwei Tian <tian.shiwei@zte.com.cn>2017-10-23 15:34:22 +0800
committerShiwei Tian <tian.shiwei@zte.com.cn>2017-10-23 15:34:22 +0800
commit75b8b484b7207c393026ee6509a22b2016a22475 (patch)
tree5dbe71ffbe2ab1ef80ac09c3c690845ca0713824
parentece7abcfdf6d68a8f41732883435822ceb745c11 (diff)
modify bug
Issue-ID: HOLMES-71 Change-Id: I1f7828319a571c78ef706220dbc2ae182f4b98ad Signed-off-by: Shiwei Tian <tian.shiwei@zte.com.cn>
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java16
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java54
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/dmaap/entity/PolicyMsg.java2
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java35
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java8
5 files changed, 67 insertions, 48 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
index df4e4ac..7cbb6f3 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
@@ -95,13 +95,14 @@ public class AaiQuery {
private String getBaseUrl(String suffixUrl) {
String url = "";
try {
- url = MicroServiceConfig.getMsbServerAddr() + suffixUrl;
+ String[] msbUrl = MicroServiceConfig.getMsbServerAddr().split(":");
+ url = msbUrl[0] + ":" + msbUrl[1] + suffixUrl;
} catch (Exception e) {
log.info("Failed to get msb address");
}
- if (url.equals("")) {
+ if ("".equals(url)) {
try {
- url = "https:\\\\" + MicroServiceConfig.getServiceAddrInfoFromCBS("aai_config")
+ url = "https://" + MicroServiceConfig.getServiceAddrInfoFromCBS("aai_config")
+ suffixUrl;
} catch (Exception e) {
log.info("Failed to get aai address");
@@ -112,9 +113,18 @@ public class AaiQuery {
private String getMsbSuffixAddr(String suffixUrl) {
String[] addrSplits = suffixUrl.substring(1).split("/");
+ String[] conv = addrSplits[2].split("-");
+ addrSplits[2] = conv[0];
+ if (conv.length > 1) {
+ for(int i = 1; i < conv.length; i++) {
+ addrSplits[2] = addrSplits[2] + conv[i].substring(0, 1).toUpperCase() + conv[i]
+ .substring(1);
+ }
+ }
String ret = addrSplits[1];
addrSplits[1] = addrSplits[0] + "-" + addrSplits[2];
addrSplits[2] = ret;
+ addrSplits[0] = "api";
StringBuffer stringBuffer = new StringBuffer();
for (String split : addrSplits) {
stringBuffer.append("/" + split);
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java
index 4dfc392..3ddf126 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java
@@ -24,6 +24,7 @@ import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.aai.AaiQuery;
+import org.onap.holmes.common.aai.entity.RelationshipList.Relationship;
import org.onap.holmes.common.aai.entity.RelationshipList.RelationshipData;
import org.onap.holmes.common.aai.entity.VmEntity;
import org.onap.holmes.common.aai.entity.VnfEntity;
@@ -71,16 +72,24 @@ public class DmaapService {
private String getVserverInstanceId(VnfEntity vnfEntity) {
String vserverInstanceId = "";
if (vnfEntity != null) {
- List<RelationshipData> relationshipDataList = vnfEntity.getRelationshipList()
- .getRelationships().stream()
- .filter(relationship -> relationship.getRelatedTo().equals("service-instance"))
- .limit(1).findFirst().get().getRelationshipDataList();
-
- vserverInstanceId = relationshipDataList.stream()
- .filter(relationshipData -> relationshipData.getRelationshipKey()
- .equals("service-instance.service-instance-id"))
- .findFirst()
- .map(relationshipData -> relationshipData.getRelationshipValue()).get();
+ List<Relationship> relationshipList = vnfEntity.getRelationshipList().getRelationships();
+ Relationship relationship = null;
+ for(int i = 0; i < relationshipList.size(); i++) {
+ if ("service-instance".equals(relationshipList.get(i).getRelatedTo())) {
+ relationship = relationshipList.get(i);
+ break;
+ }
+ }
+ if (relationship != null) {
+ List<RelationshipData> relationshipDataList = relationship.getRelationshipDataList();
+ for(int i = 0; i < relationshipDataList.size(); i++) {
+ if ("service-instance.service-instance-id"
+ .equals(relationshipDataList.get(i).getRelationshipKey())) {
+ vserverInstanceId = relationshipDataList.get(i).getRelationshipValue();
+ break;
+ }
+ }
+ }
}
return vserverInstanceId;
}
@@ -102,15 +111,16 @@ public class DmaapService {
alarmUniqueRequestID.put(rootAlarm.getSourceId(), requestID);
}
policyMsg.setClosedLoopControlName(loopControlNames.get(packageName));
- policyMsg.getAai().put("vserver.in-maint", String.valueOf(vmEntity.getInMaint()));
- policyMsg.getAai().put("vserver.is-closed-loop-disabled",
+ policyMsg.setTarget(vmEntity.getVserverName());
+ policyMsg.getAAI().put("vserver.in-maint", String.valueOf(vmEntity.getInMaint()));
+ policyMsg.getAAI().put("vserver.is-closed-loop-disabled",
String.valueOf(vmEntity.getClosedLoopDisable()));
- policyMsg.getAai().put("vserver.prov-status", vmEntity.getProvStatus());
- policyMsg.getAai().put("vserver.resource-version", vmEntity.getResourceVersion());
- policyMsg.getAai().put("vserver.vserver-id", vmEntity.getVserverId());
- policyMsg.getAai().put("vserver.vserver-name", vmEntity.getVserverName());
- policyMsg.getAai().put("vserver.vserver-name2", vmEntity.getVserverName2());
- policyMsg.getAai().put("vserver.vserver-selflink", vmEntity.getVserverSelflink());
+ policyMsg.getAAI().put("vserver.prov-status", vmEntity.getProvStatus());
+ policyMsg.getAAI().put("vserver.resource-version", vmEntity.getResourceVersion());
+ policyMsg.getAAI().put("vserver.vserver-id", vmEntity.getVserverId());
+ policyMsg.getAAI().put("vserver.vserver-name", vmEntity.getVserverName());
+ policyMsg.getAAI().put("vserver.vserver-name2", vmEntity.getVserverName2());
+ policyMsg.getAAI().put("vserver.vserver-selflink", vmEntity.getVserverSelflink());
return policyMsg;
}
@@ -118,16 +128,16 @@ public class DmaapService {
PolicyMsg policyMsg = new PolicyMsg();
policyMsg.setTarget("vserver.vserver-name");
policyMsg.setTargetType("VM");
- policyMsg.getAai().put("vserver.vserver-name", sourceName);
+ policyMsg.getAAI().put("vserver.vserver-name", sourceName);
return policyMsg;
}
private void enrichVnfInfo(VesAlarm childAlarm, PolicyMsg policyMsg) {
VnfEntity vnfEntity = getVnfEntity(childAlarm.getSourceId(), childAlarm.getSourceName());
String vserverInstatnceId = getVserverInstanceId(vnfEntity);
- policyMsg.getAai().put("generic-vnf.vnf-id", childAlarm.getSourceId());
- policyMsg.getAai().put("generic-vnf.vnf-name", childAlarm.getSourceName());
- policyMsg.getAai().put("generic-vnf.service-instance-id", vserverInstatnceId);
+ policyMsg.getAAI().put("generic-vnf.vnf-id", childAlarm.getSourceId());
+ policyMsg.getAAI().put("generic-vnf.vnf-name", childAlarm.getSourceName());
+ policyMsg.getAAI().put("generic-vnf.service-instance-id", vserverInstatnceId);
}
private VnfEntity getVnfEntity(String vnfId, String vnfName) {
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/entity/PolicyMsg.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/entity/PolicyMsg.java
index 0c3078b..4462474 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/entity/PolicyMsg.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/entity/PolicyMsg.java
@@ -40,7 +40,7 @@ public class PolicyMsg {
@JsonProperty(value = "target_type")
private String targetType = "VM";
private String target;
- private Map<String, String> aai = new HashMap<>();
+ private Map<String, String> AAI = new HashMap<>();
public static enum EVENT_STATUS {
ONSET, ABATED;
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java
index 34a6c46..7872f2b 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java
@@ -93,13 +93,14 @@ public class AaiQueryTest {
headers.put("X-FromAppId", AaiConfig.X_FROMAPP_ID);
headers.put("Authorization", AaiConfig.getAuthenticationCredentials());
headers.put("Accept", "application/json");
- String url = "host_url";
+ String url = "http://10.96.33.33/api/aai-cloudInfrastructure/v11";
when(HttpsUtils.get(url, headers)).thenReturn("{}");
PowerMockito.mockStatic(MicroServiceConfig.class);
- when(MicroServiceConfig.getMsbServerAddr()).thenReturn("host_url");
+ when(MicroServiceConfig.getMsbServerAddr()).thenReturn("http://10.96.33.33:80");
- PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2").andReturn("");
+ PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2")
+ .andReturn("/aai/v11/cloud-infrastructure");
PowerMock.replayAll();
VmEntity vmEntity = Whitebox.invokeMethod(aaiQuery, "getAaiVmData", "test1", "test2");
PowerMock.verifyAll();
@@ -125,14 +126,15 @@ public class AaiQueryTest {
headers.put("X-FromAppId", AaiConfig.X_FROMAPP_ID);
headers.put("Authorization", AaiConfig.getAuthenticationCredentials());
headers.put("Accept", "application/json");
- String url = "host_url";
+ String url = "http://10.96.33.33/api/aai-cloudInfrastructure/v11";
when(HttpsUtils.get(url, headers)).thenReturn("");
PowerMockito.mockStatic(MicroServiceConfig.class);
- when(MicroServiceConfig.getMsbServerAddr()).thenReturn("host_url");
+ when(MicroServiceConfig.getMsbServerAddr()).thenReturn("http://10.96.33.33:80");
- PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2").andReturn("");
+ PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2")
+ .andReturn("/aai/v11/cloud-infrastructure");
PowerMock.replayAll();
Whitebox.invokeMethod(aaiQuery, "getAaiVmData", "test1", "test2");
@@ -155,14 +157,15 @@ public class AaiQueryTest {
headers.put("X-FromAppId", AaiConfig.X_FROMAPP_ID);
headers.put("Authorization", AaiConfig.getAuthenticationCredentials());
headers.put("Accept", "application/json");
- String url = "host_url";
+ String url = "http://10.96.33.33/api/aai-cloudInfrastructure/v11";
when(HttpsUtils.get(url, headers)).thenThrow(new CorrelationException(""));
PowerMockito.mockStatic(MicroServiceConfig.class);
- when(MicroServiceConfig.getMsbServerAddr()).thenReturn("host_url");
+ when(MicroServiceConfig.getMsbServerAddr()).thenReturn("http://10.96.33.33:80");
- PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2").andReturn("");
+ PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2")
+ .andReturn("/aai/v11/cloud-infrastructure");
PowerMock.replayAll();
Whitebox.invokeMethod(aaiQuery, "getAaiVmData", "test1", "test2");
PowerMock.verifyAll();
@@ -277,15 +280,11 @@ public class AaiQueryTest {
headers.put("Authorization", AaiConfig.getAuthenticationCredentials());
headers.put("Accept", "application/json");
String url = "host_url";
-
when(HttpsUtils.get(url, headers)).thenThrow(new CorrelationException(""));
-
PowerMock.replayAll();
String resource = Whitebox.invokeMethod(aaiQuery, "getResponse", "host_url");
PowerMock.verifyAll();
-
assertThat(resource, equalTo(""));
-
}
@Test
@@ -308,13 +307,13 @@ public class AaiQueryTest {
aaiQuery = new AaiQuery();
PowerMockito.mockStatic(MicroServiceConfig.class);
- when(MicroServiceConfig.getMsbServerAddr()).thenReturn("msb");
+ when(MicroServiceConfig.getMsbServerAddr()).thenReturn("http://10.96.33.33:80");
when(MicroServiceConfig.getServiceAddrInfoFromCBS("nihao")).thenReturn("");
PowerMock.replayAll();
- String actual = Whitebox.invokeMethod(aaiQuery,"getBaseUrl", "url");
+ String actual = Whitebox.invokeMethod(aaiQuery,"getBaseUrl", "/url");
PowerMock.verifyAll();
- assertThat(actual, equalTo("msburl"));
+ assertThat(actual, equalTo("http://10.96.33.33/url"));
}
@Test
@@ -330,7 +329,7 @@ public class AaiQueryTest {
String actual = Whitebox.invokeMethod(aaiQuery,"getBaseUrl", "url");
System.out.println(actual);
PowerMock.verifyAll();
- assertThat(actual, equalTo("https:\\\\aaiurl"));
+ assertThat(actual, equalTo("https://aaiurl"));
}
@Test
@@ -354,7 +353,7 @@ public class AaiQueryTest {
public void testAaiQuery_getMsbSuffixAddr_Ok() throws Exception {
PowerMock.resetAll();
String url = "/aai/v11/network/generic-vnfs/generic-vnf?";
- String expect = "/aai/aai-network/v11/generic-vnfs/generic-vnf?";
+ String expect = "/api/aai-network/v11/generic-vnfs/generic-vnf?";
aaiQuery = new AaiQuery();
PowerMock.replayAll();
String actual = Whitebox.invokeMethod(aaiQuery, "getMsbSuffixAddr", url);
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java
index 3f61813..c9f892b 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java
@@ -72,7 +72,7 @@ public class DmaapServiceTest {
assertThat(policyMsg.getTarget(), equalTo("vserver.vserver-name"));
assertThat(policyMsg.getTargetType(), equalTo("VM"));
- assertThat(policyMsg.getAai().get("vserver.vserver-name"), equalTo("tetss"));
+ assertThat(policyMsg.getAAI().get("vserver.vserver-name"), equalTo("tetss"));
}
@Test
@@ -189,8 +189,8 @@ public class DmaapServiceTest {
PowerMock.verifyAll();
assertThat(actual.getClosedLoopControlName(), equalTo(null));
- assertThat(actual.getAai().get("vserver.prov-status"), equalTo("prov"));
- assertThat(actual.getAai().get("vserver.vserver-name2") == null, equalTo(true));
- assertThat(actual.getAai().get("generic-vnf.service-instance-id"), equalTo(""));
+ assertThat(actual.getAAI().get("vserver.prov-status"), equalTo("prov"));
+ assertThat(actual.getAAI().get("vserver.vserver-name2") == null, equalTo(true));
+ assertThat(actual.getAAI().get("generic-vnf.service-instance-id"), equalTo(""));
}
} \ No newline at end of file