diff options
author | Jerry Flood <jflood@att.com> | 2019-03-31 08:32:37 -0400 |
---|---|---|
committer | Jerry Flood <jflood@att.com> | 2019-03-31 08:41:13 -0400 |
commit | 80b3f339cadb72558feb0cadb249ce7046ce60ae (patch) | |
tree | 4a8b569c19959659ac628061e6ba386b3d6c1565 | |
parent | 9acaa2f04c92b6ffb0ae11a0f7b41aa260f2371d (diff) |
Commit 4 for Define OPtimizer API mS
Multiple commits required due to commit size limitation.
Change-Id: I351c5c47d628c253e84059d6e699f5a24748883f
Issue-ID: OPTFRA-437
Signed-off-by: Jerry Flood <jflood@att.com>
7 files changed, 125 insertions, 50 deletions
diff --git a/cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/availability/policies/PolicyManagerTest.java b/cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/availability/policies/PolicyManagerTest.java index 7874501..c71c829 100644 --- a/cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/availability/policies/PolicyManagerTest.java +++ b/cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/availability/policies/PolicyManagerTest.java @@ -18,6 +18,7 @@ */ package org.onap.optf.cmso.optimizer.availability.policies; + import java.util.List; import org.junit.Assert; import org.junit.Before; @@ -33,8 +34,7 @@ import org.onap.optf.cmso.optimizer.availability.policies.model.TimeLimitAndVert import org.springframework.core.env.Environment; @RunWith(MockitoJUnitRunner.class) -public class PolicyManagerTest -{ +public class PolicyManagerTest { @InjectMocks private PolicyManager policyManager; @@ -52,12 +52,11 @@ public class PolicyManagerTest public void getPolicyByName() { String policyName = "Weekday_00_06"; - String result = "CMSO.Weekday_00_06,"; + String result = "CMSO.Weekday_00_06,CMSO.Weekday_00_06,CMSO.Weekday_00_06,"; List<Policy> policies = policyManager.getSupportedPolicies(); StringBuilder sb = new StringBuilder(); - for (Policy pol : policies) - { - sb.append(pol.getPolicyName()).append("," ); + for (Policy pol : policies) { + sb.append(pol.getPolicyName()).append(","); } System.out.println(" String result = \"" + sb.toString() + "\";"); Assert.assertTrue(result.equals(sb.toString())); @@ -67,4 +66,4 @@ public class PolicyManagerTest Assert.assertTrue(top != null); } -}
\ No newline at end of file +} diff --git a/cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/availability/timewindows/RecurringWindowsTest.java b/cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/availability/timewindows/RecurringWindowsTest.java new file mode 100644 index 0000000..ce1f1a4 --- /dev/null +++ b/cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/availability/timewindows/RecurringWindowsTest.java @@ -0,0 +1,79 @@ +/* + * ============LICENSE_START============================================== + * Copyright (c) 2019 AT&T Intellectual Property. + * ======================================================================= + * 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. + * ============LICENSE_END================================================= + * + */ + +package org.onap.optf.cmso.optimizer.availability.timewindows; + +import java.time.Instant; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.optf.cmso.optimizer.availability.policies.PolicyManager; +import org.onap.optf.cmso.optimizer.availability.policies.model.TimeLimitAndVerticalTopology; +import org.onap.optf.cmso.optimizer.service.rs.models.ChangeWindow; +import org.springframework.core.env.Environment; + +@RunWith(MockitoJUnitRunner.class) +public class RecurringWindowsTest { + + + @InjectMocks + private PolicyManager policyManager; + + @Mock + public Environment env; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + Mockito.when(env.getProperty("cmso.local.policy.folder", "data/policies")).thenReturn("data/policies"); + } + + @Test + public void getAvailabilityWindowsForPolicies() { + getAvailabilityWindowsForPolicy("Weekday_00_06", "2019-03-08T00:00:00.00Z", "2019-03-12T00:00:00.00Z", 2); + getAvailabilityWindowsForPolicy("EveryDay_00_06", "2019-03-08T00:00:00.00Z", "2019-03-12T00:00:00.00Z", 4); + getAvailabilityWindowsForPolicy("Weekend_00_06", "2019-03-08T00:00:00.00Z", "2019-03-12T00:00:00.00Z", 3); + + } + + private void getAvailabilityWindowsForPolicy(String policyName, String startStr, String endStr, int size) { + TimeLimitAndVerticalTopology top = policyManager.getTimeLimitAndVerticalTopologyByName(policyName); + Assert.assertTrue(top != null); + List<TimeLimitAndVerticalTopology> topList = new ArrayList<>(); + topList.add(top); + ChangeWindow changeWindow = new ChangeWindow(); + Instant start = Instant.parse(startStr); + Instant end = Instant.parse(endStr); + changeWindow.setStartTime(Date.from(start)); + changeWindow.setEndTime(Date.from(end)); + List<ChangeWindow> windows = RecurringWindows.getAvailabilityWindowsForPolicies(topList, changeWindow); + Assert.assertTrue(windows != null); + Assert.assertTrue(windows.size() == size); + + } +} diff --git a/cmso-optimizer/src/test/java/org/onap/optf/cmso/service/rs/MockHttpServletRequest.java b/cmso-optimizer/src/test/java/org/onap/optf/cmso/service/rs/MockHttpServletRequest.java index 84e66c1..f7d0939 100644 --- a/cmso-optimizer/src/test/java/org/onap/optf/cmso/service/rs/MockHttpServletRequest.java +++ b/cmso-optimizer/src/test/java/org/onap/optf/cmso/service/rs/MockHttpServletRequest.java @@ -21,7 +21,6 @@ package org.onap.optf.cmso.service.rs; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; - import javax.servlet.http.HttpServletRequest; public class MockHttpServletRequest { diff --git a/cmso-service/etc/config/optimizer.properties b/cmso-service/etc/config/optimizer.properties index 541946e..aa79e8a 100644 --- a/cmso-service/etc/config/optimizer.properties +++ b/cmso-service/etc/config/optimizer.properties @@ -30,11 +30,11 @@ #-------------------------------------------------------------------------------
## Loopback
-cmso.optimizer.request.url=http://localhost:8080/cmso/v1/loopbacktest/optimize/schedule
-cmso.optimizer.status.url=http://localhost:8080/cmso/v1/loopbacktest/optimize/schedule
-cmso.optimizer.health.url=http://localhost:8080/cmso/v1/loopbacktest/optimize/schedule/health
+#cmso.optimizer.request.url=http://localhost:8080/cmso/v1/loopbacktest/optimize/schedule
+#cmso.optimizer.status.url=http://localhost:8080/cmso/v1/loopbacktest/optimize/schedule
+#cmso.optimizer.health.url=http://localhost:8080/cmso/v1/loopbacktest/optimize/schedule/health
## Local optimizer service
-#cmso.optimizer.request.url=http://127.0.0.1:7997/optimizer/v1/optimize/schedule
-#cmso.optimizer.status.url=http://127.0.0.1:7997/optimizer/v1/optimize/schedule
-#cmso.optimizer.health.url=http://127.0.0.1:7997/optimizer/v1/health?checkInterfaces=true
+cmso.optimizer.request.url=http://127.0.0.1:7997/optimizer/v1/optimize/schedule
+cmso.optimizer.status.url=http://127.0.0.1:7997/optimizer/v1/optimize/schedule
+cmso.optimizer.health.url=http://127.0.0.1:7997/optimizer/v1/health?checkInterfaces=true
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/model/dao/ChangeManagementDetailDAOImpl.java b/cmso-service/src/main/java/org/onap/optf/cmso/model/dao/ChangeManagementDetailDAOImpl.java index 028241c..2543c77 100644 --- a/cmso-service/src/main/java/org/onap/optf/cmso/model/dao/ChangeManagementDetailDAOImpl.java +++ b/cmso-service/src/main/java/org/onap/optf/cmso/model/dao/ChangeManagementDetailDAOImpl.java @@ -1,27 +1,27 @@ /*
* Copyright © 2017-2018 AT&T Intellectual Property.
* Modifications Copyright © 2018 IBM.
- *
+ *
* 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.
- *
- *
+ *
+ *
* Unless otherwise specified, all documentation contained herein is licensed
* under the Creative Commons License, Attribution 4.0 Intl. (the "License");
* you may not use this documentation except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* https://creativecommons.org/licenses/by/4.0/
- *
+ *
* Unless required by applicable law or agreed to in writing, documentation
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -65,11 +65,13 @@ public class ChangeManagementDetailDAOImpl implements ChangeManagementDetailDAO + " left outer join APPROVAL_TYPES at on sa.approval_types_uuid = at.uuid ");
sql.append(where);
sql.append(" order by uuid ");
- if (limit > 0)
+ if (limit > 0) {
sql.append("LIMIT " + limit);
+ }
- Query q = manager.createNativeQuery(sql.toString(), ChangeManagementDetail.class);
- List<ChangeManagementDetail> list = q.getResultList();
+ Query query = manager.createNativeQuery(sql.toString(), ChangeManagementDetail.class);
+ @SuppressWarnings("unchecked")
+ List<ChangeManagementDetail> list = query.getResultList();
return list;
}
}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/CmsoOptimizerClient.java b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/CmsoOptimizerClient.java index 4db44f6..1c3505e 100644 --- a/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/CmsoOptimizerClient.java +++ b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/CmsoOptimizerClient.java @@ -180,8 +180,7 @@ public class CmsoOptimizerClient { debug.debug("Successfully scheduled optimization: " + schedule.getScheduleId()); // Scheduled with optimizer break; - case 400: // Bad request - { + case 400: { schedule.setOptimizerDateTimeMillis(System.currentTimeMillis()); schedule.setOptimizerStatus("HTTP Status: " + response.getStatus()); String message = response.readEntity(String.class); @@ -287,8 +286,7 @@ public class CmsoOptimizerClient { debug.debug("Successfully retrieved optimization: " + schedule.getScheduleId()); optimizerHandler.handleOptimizerResponse(optimizerResponse, schedule); break; - default: // Bad request - { + default: { schedule.setOptimizerDateTimeMillis(System.currentTimeMillis()); schedule.setOptimizerStatus("HTTP Status: " + response.getStatus()); String message = response.readEntity(String.class); @@ -336,8 +334,7 @@ public class CmsoOptimizerClient { return null; } - private List<OptimizerElementInfo> marshallElements(SchedulingData info) - { + private List<OptimizerElementInfo> marshallElements(SchedulingData info) { List<OptimizerElementInfo> list = new ArrayList<>(); List<ElementInfo> elementList = info.getElements(); for (ElementInfo element : elementList) { @@ -345,7 +342,7 @@ public class CmsoOptimizerClient { optElement.setElementData(element.getElementData()); optElement.setElementId(element.getElementId()); optElement.setGroupId(element.getGroupId()); - list.add(optElement ); + list.add(optElement); } return list; } @@ -375,6 +372,7 @@ public class CmsoOptimizerClient { /** * Health check. + * * @return */ public HealthCheckComponent healthCheck() { diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/OptimizerQuartzJob.java b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/OptimizerQuartzJob.java index 48d6e73..71a2092 100644 --- a/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/OptimizerQuartzJob.java +++ b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/OptimizerQuartzJob.java @@ -66,10 +66,9 @@ public class OptimizerQuartzJob extends QuartzJobBean { private static EELFLogger log = EELFManager.getInstance().getLogger(OptimizerQuartzJob.class);
private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();
private static EELFLogger errors = EELFManager.getInstance().getErrorLogger();
- private static EELFLogger metrics = EELFManager.getInstance().getMetricsLogger();
@Autowired
- ScheduleDAO scheduleDAO;
+ ScheduleDAO scheduleDao;
@Autowired
PropertiesManagement pm;
@@ -88,20 +87,20 @@ public class OptimizerQuartzJob extends QuartzJobBean { // return;
try {
- // This job will look at the schedules waiting to go to Optimizer or waiting on response from optimizer
+ // This job will look at the schedules waiting to go to Optimizer or waiting on response from
+ // optimizer
// (PendingSchedule, PendingOptimizer),
// schedule the request and update the status to PendingSchedule
// and update the state to OptimizationInProgress
- List<Schedule> schedules = scheduleDAO.findByDomainStatus(DomainsEnum.ChangeManagement.toString(),
- CMSStatusEnum.PendingSchedule.toString());
+ List<Schedule> schedules = scheduleDao.findByDomainStatus(DomainsEnum.ChangeManagement.toString(),
+ CMSStatusEnum.PendingSchedule.toString());
for (Schedule s : schedules) {
scheduleOptimization(s);
}
- List<Schedule> inProgressSchedules = scheduleDAO.findByDomainStatus(DomainsEnum.ChangeManagement.toString(),
- CMSStatusEnum.OptimizationInProgress.toString());
- for (Schedule s : inProgressSchedules)
- {
- scheduleOptimization(s);
+ List<Schedule> inProgressSchedules = scheduleDao.findByDomainStatus(DomainsEnum.ChangeManagement.toString(),
+ CMSStatusEnum.OptimizationInProgress.toString());
+ for (Schedule s : inProgressSchedules) {
+ scheduleOptimization(s);
}
} catch (Exception e) {
@@ -136,7 +135,7 @@ public class OptimizerQuartzJob extends QuartzJobBean { default: {
throw new SchedulerException(
- "Invalid return from dispach service: " + url + " : " + response.toString());
+ "Invalid return from dispach service: " + url + " : " + response.toString());
}
}
} catch (Exception e) {
@@ -149,18 +148,17 @@ public class OptimizerQuartzJob extends QuartzJobBean { }
/**
- * According to the documentation I read, Quartz would queue a job without
- * waiting for the completion of the job with @DisallowConcurrentExecution to
- * complete so that there would be a backlog of triggers to process
+ * According to the documentation I read, Quartz would queue a job without waiting for the
+ * completion of the job with @DisallowConcurrentExecution to complete so that there would be a
+ * backlog of triggers to process
*
- * This was designed to spin though these stale triggers. When this didn't work,
- * I discovered that the behavior is that Quartz will wait for the appropriate
- * interval after @DisallowConcurrentExecution jobs complete.
+ * This was designed to spin though these stale triggers. When this didn't work, I discovered that
+ * the behavior is that Quartz will wait for the appropriate interval
+ * after @DisallowConcurrentExecution jobs complete.
*
* I tested by adding a sleep for an interval > the trigger interval
*
- * QUartz appears to do what makes sense. Leaving this here in case issues
- * arise...
+ * QUartz appears to do what makes sense. Leaving this here in case issues arise...
*
*/
@SuppressWarnings("unused")
|