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;
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
if (null == rule) {\r
return;\r
}\r
-\r
this.rules.add(rule);\r
}\r
\r
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;
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) {
import javax.ws.rs.core.Response;\r
import lombok.Getter;\r
import lombok.Setter;\r
+import org.apache.http.HttpStatus;\r
import org.glassfish.jersey.client.ClientConfig;\r
import org.jvnet.hk2.annotations.Service;\r
import org.onap.holmes.common.dmaap.entity.PolicyMsg;\r
try {\r
content = mapper.writeValueAsString(msg);\r
} catch (JsonProcessingException e) {\r
- throw new CorrelationException("Failed to convert the message object to a json string.", e);\r
+ throw new CorrelationException("Failed to convert the message object to a json string.",\r
+ e);\r
}\r
-\r
WebTarget webTarget = client.target(url);\r
Response response = webTarget.request(MediaType.APPLICATION_JSON)\r
.post(Entity.entity(content, MediaType.APPLICATION_JSON));\r
-\r
return checkStatus(response);\r
}\r
\r
private boolean checkStatus(Response response) {\r
- return false;\r
+ return (response.getStatus() == HttpStatus.SC_OK) ? true : false;\r
}\r
}\r
--- /dev/null
+/*
+ * 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 static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
+import org.onap.holmes.common.dcae.entity.SecurityInfo;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@PrepareForTest(DcaeConfigurationsCache.class)
+@RunWith(PowerMockRunner.class)
+public class DcaeConfigurationsCacheTest {
+
+ @Test
+ public void testDcaeConfigurationsCache() {
+ DcaeConfigurations dcaeConfigurations = new DcaeConfigurations();
+ SecurityInfo securityInfo = new SecurityInfo();
+ securityInfo.setAafUsername("tset11");
+ dcaeConfigurations.addPubSecInfo("test", securityInfo);
+ DcaeConfigurationsCache.setDcaeConfigurations(dcaeConfigurations);
+ assertThat(DcaeConfigurationsCache.getPubSecInfo("test").getAafUsername(),
+ equalTo(securityInfo.getAafUsername()));
+ }
+}
\ No newline at end of file
import java.util.ArrayList;
import java.util.List;
import org.junit.runner.RunWith;
+import org.omg.CORBA.Any;
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.VnfEntity;
import org.onap.holmes.common.api.stat.VesAlarm;
import org.onap.holmes.common.exception.CorrelationException;
+import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.junit.Before;
@Rule
public ExpectedException thrown = ExpectedException.none();
- private Publisher publisher;
-
private AaiQuery aaiQuery;
private DmaapService dmaapService;
@Before
public void setUp() {
dmaapService = new DmaapService();
- publisher = PowerMock.createMock(Publisher.class);
- Whitebox.setInternalState(dmaapService, "publisher", publisher);
aaiQuery = PowerMock.createMock(AaiQuery.class);
Whitebox.setInternalState(dmaapService, "aaiQuery", aaiQuery);
}
- @Test
- public void testDmaapService_publish_ok() throws Exception {
- PowerMock.resetAll();
- PolicyMsg policyMsg = new PolicyMsg();
- PowerMock.expectPrivate(publisher, "publish", anyObject(PolicyMsg.class)).andReturn(true)
- .anyTimes();
- PowerMock.replayAll();
- Whitebox.invokeMethod(dmaapService, "publishPolicyMsg", policyMsg);
- PowerMock.verifyAll();
- }
-
- @Test
- public void testDmaapService_publish_exception() throws Exception {
- PowerMock.resetAll();
- final PolicyMsg policyMsg = new PolicyMsg();
- PowerMock.expectPrivate(publisher, "publish", policyMsg)
- .andThrow(new CorrelationException("")).anyTimes();
- PowerMock.replayAll();
- Whitebox.invokeMethod(dmaapService, "publishPolicyMsg", policyMsg);
- PowerMock.verifyAll();
- }
-
@Test
public void testDmaapService_getDefaultPolicyMsg_ok() throws Exception {
PowerMock.resetAll();