diff options
author | 2017-10-13 14:11:57 +0800 | |
---|---|---|
committer | 2017-10-13 20:54:25 +0800 | |
commit | 105437a89bd5bcfcaf40dac25e2c087aafb0996b (patch) | |
tree | f9bd5427225d5205166a9c091fb8244eaf003b73 /holmes-actions/src/main | |
parent | 7b42bb15c5ed414fd465af8c836ae63abb8b21c0 (diff) |
modify not publish messages to DMaaP
Issue-ID: HOLMES-71
Change-Id: I96097090b5d2ba2ab611ccb326e4670eba39cea7
Signed-off-by: Shiwei Tian <tian.shiwei@zte.com.cn>
Diffstat (limited to 'holmes-actions/src/main')
6 files changed, 90 insertions, 8 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 074c509..fb8a8ca 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 @@ -15,7 +15,6 @@ package org.onap.holmes.common.aai; import java.util.HashMap; import java.util.Map; -import java.util.stream.Stream; import javax.inject.Inject; import lombok.extern.slf4j.Slf4j; import org.jvnet.hk2.annotations.Service; diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationQuery.java b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationQuery.java new file mode 100644 index 0000000..1576215 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationQuery.java @@ -0,0 +1,45 @@ +/* + * Copyright 2017 ZTE Corporation. + * + * 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.holmes.common.dcae; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.ClientConfig; +import org.jvnet.hk2.annotations.Service; +import org.onap.holmes.common.config.MicroServiceConfig; +import org.onap.holmes.common.dcae.entity.DcaeConfigurations; +import org.onap.holmes.common.dcae.utils.DcaeConfigurationParser; +import org.onap.holmes.common.exception.CorrelationException; + +public class DcaeConfigurationQuery { + + public static DcaeConfigurations getDcaeConfigurations(String hostname) + throws CorrelationException { + String serviceAddrInfo = MicroServiceConfig.getServiceAddrInfoFromCBS(hostname); + String response = getDcaeResponse(serviceAddrInfo); + DcaeConfigurations dcaeConfigurations = null; + dcaeConfigurations = DcaeConfigurationParser.parse(response); + return dcaeConfigurations; + } + + private static String getDcaeResponse(String serviceAddrInfo) { + Client client = ClientBuilder.newClient(new ClientConfig()); + WebTarget webTarget = client.target(serviceAddrInfo); + return webTarget.request("application/json").get() + .readEntity(String.class); + } +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationsCache.java b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationsCache.java new file mode 100644 index 0000000..2564e23 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationsCache.java @@ -0,0 +1,35 @@ +/* + * Copyright 2017 ZTE Corporation. + * + * 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.holmes.common.dcae; + +import org.onap.holmes.common.dcae.entity.DcaeConfigurations; +import org.onap.holmes.common.dcae.entity.SecurityInfo; + +public class DcaeConfigurationsCache { + + private static DcaeConfigurations dcaeConfigurations; + + public synchronized static SecurityInfo getPubSecInfo(String key) { + if (dcaeConfigurations != null) { + return dcaeConfigurations.getPubSecInfo(key); + } + return null; + } + + public synchronized static void setDcaeConfigurations(DcaeConfigurations configurations) { + dcaeConfigurations = configurations; + } +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/entity/DcaeConfigurations.java b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/entity/DcaeConfigurations.java index b08261f..f1307c4 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/entity/DcaeConfigurations.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/entity/DcaeConfigurations.java @@ -32,7 +32,6 @@ public class DcaeConfigurations extends HashMap<String, Object>{ if (null == rule) {
return;
}
-
this.rules.add(rule);
}
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 05b3583..64b7dbc 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 @@ -27,6 +27,7 @@ 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; import org.onap.holmes.common.api.stat.VesAlarm; +import org.onap.holmes.common.dcae.DcaeConfigurationsCache; import org.onap.holmes.common.dmaap.entity.PolicyMsg; import org.onap.holmes.common.dmaap.entity.PolicyMsg.EVENT_STATUS; import org.onap.holmes.common.exception.CorrelationException; @@ -37,15 +38,18 @@ import org.onap.holmes.common.utils.JacksonUtil; public class DmaapService { public static final int POLICY_MESSAGE_ABATED = 1; + + public static final String PUBLISHER_KEY = "unauthenticated.DCAE_CL_OUTPUT"; + @Inject private AaiQuery aaiQuery; - @Inject - private Publisher publisher; public static ConcurrentHashMap<String, String> loopControlNames = new ConcurrentHashMap<>(); public void publishPolicyMsg(PolicyMsg policyMsg) { try { + Publisher publisher = new Publisher(); + publisher.setUrl(DcaeConfigurationsCache.getPubSecInfo(PUBLISHER_KEY).getDmaapInfo().getTopicUrl()); publisher.publish(policyMsg); log.info("send policyMsg: " + JacksonUtil.beanToJson(policyMsg)); } catch (CorrelationException e) { diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java index 035ecaa..285c3d6 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java @@ -25,6 +25,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response;
import lombok.Getter;
import lombok.Setter;
+import org.apache.http.HttpStatus;
import org.glassfish.jersey.client.ClientConfig;
import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.dmaap.entity.PolicyMsg;
@@ -47,17 +48,16 @@ public class Publisher { try {
content = mapper.writeValueAsString(msg);
} catch (JsonProcessingException e) {
- throw new CorrelationException("Failed to convert the message object to a json string.", e);
+ throw new CorrelationException("Failed to convert the message object to a json string.",
+ e);
}
-
WebTarget webTarget = client.target(url);
Response response = webTarget.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(content, MediaType.APPLICATION_JSON));
-
return checkStatus(response);
}
private boolean checkStatus(Response response) {
- return false;
+ return (response.getStatus() == HttpStatus.SC_OK) ? true : false;
}
}
|