summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rulemgt-frontend/.angular-cli.json1
-rw-r--r--rulemgt-frontend/src/app/correlation-ruleList/alarmRule.component.ts4
-rw-r--r--rulemgt-standalone/src/main/assembly/dbscripts/postgresql/onap-holmes_rulemgt-createobj.sql2
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java20
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java223
-rw-r--r--rules/ccvnp-rule.drl25
6 files changed, 179 insertions, 96 deletions
diff --git a/rulemgt-frontend/.angular-cli.json b/rulemgt-frontend/.angular-cli.json
index 5da3c0f..e18a89f 100644
--- a/rulemgt-frontend/.angular-cli.json
+++ b/rulemgt-frontend/.angular-cli.json
@@ -27,6 +27,7 @@
"assets/framework/browser/thirdparty/css/magic-check.css"
],
"scripts": [
+ "../node_modules/jquery/dist/jquery.js",
"assets/common/js/jQuery-File-Upload/js/jquery.ui.widget.js",
"assets/common/js/jQuery-File-Upload/js/vendor/jquery.ui.widget.js",
"assets/common/js/jQuery-File-Upload/js/jquery.iframe-transport.js",
diff --git a/rulemgt-frontend/src/app/correlation-ruleList/alarmRule.component.ts b/rulemgt-frontend/src/app/correlation-ruleList/alarmRule.component.ts
index fa69e3c..cb413b5 100644
--- a/rulemgt-frontend/src/app/correlation-ruleList/alarmRule.component.ts
+++ b/rulemgt-frontend/src/app/correlation-ruleList/alarmRule.component.ts
@@ -20,8 +20,6 @@ import {RuleRequest} from './ruleRequest';
import {Router} from '@angular/router';
import {AlarmRuleService} from './alarmRule.service';
-declare var jQuery: any;
-
@Component({
selector: 'alarmRule',
templateUrl: './alarmRule.component.html',
@@ -69,7 +67,7 @@ export class AlarmRule implements OnInit {
this.ruleRequest.enabled = 0;
} else {
this.activeText = "option_all";
- this.ruleRequest.enabled = null;
+ this.ruleRequest.enabled = 2;
}
}
diff --git a/rulemgt-standalone/src/main/assembly/dbscripts/postgresql/onap-holmes_rulemgt-createobj.sql b/rulemgt-standalone/src/main/assembly/dbscripts/postgresql/onap-holmes_rulemgt-createobj.sql
index feaacd6..090734c 100644
--- a/rulemgt-standalone/src/main/assembly/dbscripts/postgresql/onap-holmes_rulemgt-createobj.sql
+++ b/rulemgt-standalone/src/main/assembly/dbscripts/postgresql/onap-holmes_rulemgt-createobj.sql
@@ -41,7 +41,7 @@ CREATE TABLE APLUS_RULE (
UPDATOR VARCHAR(20) NULL,
UPDATETIME TIMESTAMP NULL,
PARAMS VARCHAR(4000) NULL,
- CONTENT VARCHAR(4000) NOT NULL,
+ CONTENT VARCHAR(20000) NOT NULL,
VENDOR VARCHAR(100) NOT NULL,
ENGINEINSTANCE VARCHAR(100) NOT NULL,
PACKAGE VARCHAR(255) NULL,
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java
index 2d63bb6..6c0d732 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java
@@ -1,11 +1,11 @@
/**
* Copyright 2017 ZTE Corporation.
- *
+ * <p>
* 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
- *
+ * <p>
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
* 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
@@ -21,12 +21,14 @@ import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken;
+
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import javax.ws.rs.core.MediaType;
+
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpDelete;
@@ -68,8 +70,8 @@ public class DcaeConfigurationPolling implements Runnable {
try {
dcaeConfigurations = DcaeConfigurationQuery.getDcaeConfigurations(hostname);
String md5 = Md5Util.md5(dcaeConfigurations);
- if (prevResult && prevConfigMd5.equals(md5)){
- log.info("Operation aborted due to identical Configurations.");
+ if (prevResult && prevConfigMd5.equals(md5)) {
+ log.info("Operation aborted due to identical configurations.");
return;
}
prevConfigMd5 = md5;
@@ -104,7 +106,7 @@ public class DcaeConfigurationPolling implements Runnable {
}
public RuleQueryListResponse getAllCorrelationRules() throws CorrelationException, IOException {
- HashMap<String, String> headers = new HashMap<>();
+ HashMap<String, String> headers = new HashMap<>();
headers.put("Content-Type", MediaType.APPLICATION_JSON);
CloseableHttpClient httpClient = null;
HttpGet httpGet = new HttpGet(url);
@@ -112,7 +114,7 @@ public class DcaeConfigurationPolling implements Runnable {
httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);
HttpResponse httpResponse = HttpsUtils.get(httpGet, headers, httpClient);
String response = HttpsUtils.extractResponseEntity(httpResponse);
- return JSON.parseObject(response,RuleQueryListResponse.class);
+ return JSON.parseObject(response, RuleQueryListResponse.class);
} finally {
httpGet.releaseConnection();
closeHttpClient(httpClient);
@@ -157,8 +159,8 @@ public class DcaeConfigurationPolling implements Runnable {
return suc;
}
- private void deleteAllCorrelationRules(List<RuleResult4API> ruleResult4APIs){
- ruleResult4APIs.forEach(correlationRule ->{
+ private void deleteAllCorrelationRules(List<RuleResult4API> ruleResult4APIs) {
+ ruleResult4APIs.forEach(correlationRule -> {
HashMap<String, String> headers = new HashMap<>();
headers.put("Content-Type", MediaType.APPLICATION_JSON);
CloseableHttpClient httpClient = null;
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java
index 1037495..52f1e37 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java
@@ -1,12 +1,12 @@
/**
* Copyright 2017 ZTE Corporation.
- *
+ * <p>
* 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* 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.
@@ -15,103 +15,176 @@
*/
package org.onap.holmes.rulemgt.dcae;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.junit.Assert.assertThat;
-import static org.powermock.api.mockito.PowerMockito.when;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.http.HttpResponse;
+import org.apache.http.StatusLine;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
-import org.onap.holmes.common.config.MicroServiceConfig;
+import org.onap.holmes.common.dcae.DcaeConfigurationQuery;
import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
import org.onap.holmes.common.dcae.entity.Rule;
-import org.onap.holmes.common.dcae.utils.DcaeConfigurationParser;
-import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
-import org.powermock.api.easymock.PowerMock;
-import org.powermock.api.mockito.PowerMockito;
+import org.onap.holmes.common.utils.HttpsUtils;
+import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
+import org.onap.holmes.rulemgt.bean.response.RuleResult4API;
import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
-@PrepareForTest({DcaeConfigurationPolling.class, MicroServiceConfig.class})
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.expect;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.powermock.api.easymock.PowerMock.*;
+
+@PrepareForTest({HttpsUtils.class, DcaeConfigurationQuery.class, DcaeConfigurationPolling.class})
+@SuppressStaticInitializationFor("org.onap.holmes.common.utils.HttpsUtils")
@RunWith(PowerMockRunner.class)
public class DcaeConfigurationPollingTest {
@org.junit.Rule
public ExpectedException thrown = ExpectedException.none();
- private DcaeConfigurationPolling daceConfigurationPolling;
+ @Test
+ public void run() throws Exception {
+ DcaeConfigurations dcaeConfigurations = new DcaeConfigurations();
+ dcaeConfigurations.addDefaultRule(new Rule("test", "clName", "contents", 1));
+ mockStatic(DcaeConfigurationQuery.class);
+ expect(DcaeConfigurationQuery.getDcaeConfigurations(anyObject(String.class))).andReturn(dcaeConfigurations);
+ DcaeConfigurationPolling dcaeConfigurationPolling = createPartialMock(DcaeConfigurationPolling.class,
+ "getAllCorrelationRules");
+ Whitebox.setInternalState(dcaeConfigurationPolling, "url", "http://127.0.0.1");
- @Before
- public void setUp() {
- daceConfigurationPolling = new DcaeConfigurationPolling("holmes-rule-mgmt");
- }
+ RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse();
+ List<RuleResult4API> ruleResult4APIList = new ArrayList<RuleResult4API>(){
+ {
+ add(new RuleResult4API());
+ }
+ };
+ ruleQueryListResponse.setCorrelationRules(ruleResult4APIList);
+ ruleQueryListResponse.setTotalCount(ruleResult4APIList.size());
+ expect(dcaeConfigurationPolling.getAllCorrelationRules()).andReturn(ruleQueryListResponse);
- @Test
- public void testDaceConfigurationPolling_getDcaeConfigurations_exception() throws Exception {
- PowerMock.resetAll();
- thrown.expect(CorrelationException.class);
- thrown.expectMessage("syntax error, pos 1");
- PowerMockito.mockStatic(MicroServiceConfig.class);
- when(MicroServiceConfig.getServiceConfigInfoFromCBS("holmes-rule-mgmt"))
- .thenReturn("host");
- PowerMock.createMock(DcaeConfigurationParser.class);
- PowerMock.expectPrivate(DcaeConfigurationParser.class, "parse", "host")
- .andThrow(new CorrelationException("tests")).anyTimes();
-
- PowerMock.replayAll();
- Whitebox.invokeMethod(daceConfigurationPolling, "getDcaeConfigurations");
- PowerMock.verifyAll();
- }
+ CloseableHttpClient clientMock = createMock(CloseableHttpClient.class);
+ HttpResponse httpResponseMock = createMock(HttpResponse.class);
+ expect(HttpsUtils.getHttpClient(30000)).andReturn(clientMock);
+ expect(HttpsUtils.delete(anyObject(HttpDelete.class), anyObject(HashMap.class), anyObject(CloseableHttpClient.class)))
+ .andReturn(httpResponseMock);
+ clientMock.close();
+ expectLastCall();
- @Test
- public void testDaceConfigurationPolling_getDcaeConfigurations_null() throws Exception {
- PowerMock.resetAll();
- thrown.expect(CorrelationException.class);
- PowerMockito.mockStatic(MicroServiceConfig.class);
- when(MicroServiceConfig.getServiceConfigInfoFromCBS("holmes-rule-mgmt"))
- .thenReturn("host");
- PowerMock.createMock(DcaeConfigurationParser.class);
- PowerMock.expectPrivate(DcaeConfigurationParser.class, "parse", "host")
- .andReturn(null).anyTimes();
-
- PowerMock.replayAll();
- DcaeConfigurations dcaeConfigurations = Whitebox
- .invokeMethod(daceConfigurationPolling, "getDcaeConfigurations");
- PowerMock.verifyAll();
-
- assertThat(dcaeConfigurations == null, equalTo(true));
+ expect(HttpsUtils.getHttpClient(30000)).andReturn(clientMock);
+ expect(HttpsUtils.put(anyObject(HttpPut.class), anyObject(HashMap.class), anyObject(HashMap.class),
+ anyObject(StringEntity.class), anyObject(CloseableHttpClient.class)))
+ .andReturn(httpResponseMock);
+ clientMock.close();
+ expectLastCall();
+
+ StatusLine sl = createMock(StatusLine.class);
+ expect(httpResponseMock.getStatusLine()).andReturn(sl);
+ expect(sl.getStatusCode()).andReturn(200);
+
+ replayAll();
+
+ dcaeConfigurationPolling.run();
+
+ verifyAll();
}
@Test
- public void testDaceConfigurationPolling_addAllCorrelationRules_connection_exception()
- throws Exception {
- PowerMock.resetAll();
- thrown.expect(CorrelationException.class);
+ public void run_identical_contents() throws Exception {
DcaeConfigurations dcaeConfigurations = new DcaeConfigurations();
- Rule rule = new Rule("test", "test", "tset",1);
- dcaeConfigurations.getDefaultRules().add(rule);
+ dcaeConfigurations.addDefaultRule(new Rule("test", "clName", "contents", 1));
+ mockStatic(DcaeConfigurationQuery.class);
+ expect(DcaeConfigurationQuery.getDcaeConfigurations(anyObject(String.class))).andReturn(dcaeConfigurations).times(2);
+ DcaeConfigurationPolling dcaeConfigurationPolling = createPartialMock(DcaeConfigurationPolling.class,
+ "getAllCorrelationRules");
+ Whitebox.setInternalState(dcaeConfigurationPolling, "url", "http://127.0.0.1");
- PowerMock.replayAll();
- Whitebox.invokeMethod(daceConfigurationPolling, "addAllCorrelationRules",
- dcaeConfigurations);
- PowerMock.verifyAll();
+ RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse();
+ List<RuleResult4API> ruleResult4APIList = new ArrayList<RuleResult4API>(){
+ {
+ add(new RuleResult4API());
+ }
+ };
+ ruleQueryListResponse.setCorrelationRules(ruleResult4APIList);
+ ruleQueryListResponse.setTotalCount(ruleResult4APIList.size());
+ expect(dcaeConfigurationPolling.getAllCorrelationRules()).andReturn(ruleQueryListResponse);
+
+ CloseableHttpClient clientMock = createMock(CloseableHttpClient.class);
+ HttpResponse httpResponseMock = createMock(HttpResponse.class);
+ expect(HttpsUtils.getHttpClient(30000)).andReturn(clientMock);
+ expect(HttpsUtils.delete(anyObject(HttpDelete.class), anyObject(HashMap.class), anyObject(CloseableHttpClient.class)))
+ .andReturn(httpResponseMock);
+ clientMock.close();
+ expectLastCall();
+
+ expect(HttpsUtils.getHttpClient(30000)).andReturn(clientMock);
+ expect(HttpsUtils.put(anyObject(HttpPut.class), anyObject(HashMap.class), anyObject(HashMap.class),
+ anyObject(StringEntity.class), anyObject(CloseableHttpClient.class)))
+ .andReturn(httpResponseMock);
+ clientMock.close();
+ expectLastCall();
+
+ StatusLine sl = createMock(StatusLine.class);
+ expect(httpResponseMock.getStatusLine()).andReturn(sl);
+ expect(sl.getStatusCode()).andReturn(200);
+
+ replayAll();
+
+ dcaeConfigurationPolling.run();
+ dcaeConfigurationPolling.run();
+
+ verifyAll();
}
+
+
@Test
- public void testDaceConfigurationPolling_getRuleCreateRequest() throws Exception {
- PowerMock.resetAll();
- Rule rule = new Rule("test", "test1", "stest",1);
- PowerMock.replayAll();
- RuleCreateRequest actual = Whitebox
- .invokeMethod(daceConfigurationPolling, "getRuleCreateRequest", rule);
- PowerMock.verifyAll();
-
- assertThat(actual.getRuleName(), equalTo("test"));
- assertThat(actual.getLoopControlName(), equalTo("test1"));
- assertThat(actual.getContent(), equalTo("stest"));
- assertThat(actual.getDescription(), equalTo(""));
- assertThat(actual.getEnabled(), equalTo(1));
+ public void getAllCorrelationRules() throws Exception {
+ Map<String, Object> responseObj = new HashMap(){
+ {
+ put("correlationRules", new ArrayList<String>());
+ put("totalCount", 0);
+ }
+ };
+
+ CloseableHttpClient clientMock = createMock(CloseableHttpClient.class);
+ HttpResponse httpResponseMock = createMock(HttpResponse.class);
+ expect(HttpsUtils.getHttpClient(30000)).andReturn(clientMock);
+ expect(HttpsUtils.get(anyObject(HttpGet.class), anyObject(HashMap.class), anyObject(CloseableHttpClient.class)))
+ .andReturn(httpResponseMock);
+ expect(HttpsUtils.extractResponseEntity(httpResponseMock)).andReturn(JSONObject.toJSONString(responseObj));
+ clientMock.close();
+ expectLastCall();
+
+ replayAll();
+ DcaeConfigurationPolling daceConfigurationPolling = new DcaeConfigurationPolling("holmes-rule-mgmt");
+ RuleQueryListResponse response = daceConfigurationPolling.getAllCorrelationRules();
+ assertThat(response.getTotalCount(), is(0));
+ verifyAll();
+ }
+
+ @Before
+ public void setUp() {
+ mockStatic(HttpsUtils.class);
+ }
+
+ @After
+ public void tearDown() {
+ resetAll();
}
} \ No newline at end of file
diff --git a/rules/ccvnp-rule.drl b/rules/ccvnp-rule.drl
index 9de2491..e006dbb 100644
--- a/rules/ccvnp-rule.drl
+++ b/rules/ccvnp-rule.drl
@@ -36,7 +36,7 @@ function String getLogicLink(VesAlarm alarm) {
getAdditionalField(alarm, "networkId"),
getAdditionalField(alarm, "node"),
getAdditionalField(alarm, "tp-id"),
- getAdditionalField(alarm, "oper-status")
+ null
);
}
@@ -54,8 +54,7 @@ function boolean isCorrelated(VesAlarm a, VesAlarm b) {
return logicLinkA.equals(logicLinkB);
}
-function void updateAaiStatus(String networkId, String pnfName, String ifName,
- String linkName, String status) {
+function void updateAaiLinkStatus(String linkName, String status) {
AaiQuery4Ccvpn aai = AaiQuery4Ccvpn.newInstance();
Map<String, Object> body = new HashMap<String, Object>(){
{
@@ -63,6 +62,15 @@ function void updateAaiStatus(String networkId, String pnfName, String ifName,
}
};
aai.updateLogicLinkStatus(linkName, body);
+}
+
+function void updateAaiTpStatus(String networkId, String pnfName, String ifName, String status) {
+ AaiQuery4Ccvpn aai = AaiQuery4Ccvpn.newInstance();
+ Map<String, Object> body = new HashMap<String, Object>(){
+ {
+ put("operational-status", status);
+ }
+ };
aai.updateTerminalPointStatus(networkId, pnfName, ifName, body);
}
@@ -78,7 +86,7 @@ function Map<String, Object> getAdditionalResourceInfo(String networkId, String
JSONObject o = instances.getJSONObject(i);
String name = o.getString("service-instance-name");
String id = o.getString("service-instance-id");
- ret.put(name + ".input-parameters", o.getString("input-parameters"));
+ ret.put(id + ".input-parameters", o.getString("input-parameters"));
sbn.append(name).append(",");
sbi.append(id).append(",");
}
@@ -119,11 +127,10 @@ rule "Update AAI Information"
when
$a: VesAlarm(eventName.indexOf("Fault_Route_Status") != -1)
then
- updateAaiStatus (
+ updateAaiTpStatus (
getAdditionalField($a, "networkId"),
getAdditionalField($a, "node"),
getAdditionalField($a, "tp-id"),
- getLogicLink($a),
getAdditionalField($a, "oper-status")
);
end
@@ -139,14 +146,16 @@ rule "Set Up Correlation"
eventName.indexOf("Fault_Route_Status") != -1,
Math.abs(startEpochMicrosec - $start) < 60000)
then
- if ("down".equalsIgnoreCase(getAdditionalField($a, "oper-status"))
- && "down".equalsIgnoreCase(getAdditionalField($b, "oper-status"))) {
+ String status = "down";
+ if (status.equalsIgnoreCase(getAdditionalField($a, "oper-status"))
+ && status.equalsIgnoreCase(getAdditionalField($b, "oper-status"))) {
if (isCorrelated($a, $b)){
// If any of the alarms have been marked as root, a policy message has ever been created and sent. Do NOT send it again.
if ($a.getRootFlag() != 1 && $b.getRootFlag() != 1) {
PolicyMsg msg = createPolicyMsg($a);
DmaapService dmaapService = ServiceLocatorHolder.getLocator().getService(DmaapService.class);
dmaapService.publishPolicyMsg(msg, "unauthenticated.DCAE_CL_OUTPUT");
+ updateAaiLinkStatus(getLogicLink($a), status);
}
$a.setRootFlag(1);
$b.setRootFlag(1);