Multiple commits required due to commit size limitation.
Change-Id: I351c5c47d628c253e84059d6e699f5a24748883f
Issue-ID: OPTFRA-437
Signed-off-by: Jerry Flood <jflood@att.com>
*/
package org.onap.optf.cmso.optimizer.availability.policies;
+
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.springframework.core.env.Environment;
@RunWith(MockitoJUnitRunner.class)
-public class PolicyManagerTest
-{
+public class PolicyManagerTest {
@InjectMocks
private PolicyManager policyManager;
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()));
Assert.assertTrue(top != null);
}
-}
\ No newline at end of file
+}
--- /dev/null
+/*
+ * ============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);
+
+ }
+}
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-
import javax.servlet.http.HttpServletRequest;
public class MockHttpServletRequest {
#-------------------------------------------------------------------------------\r
\r
## Loopback \r
-cmso.optimizer.request.url=http://localhost:8080/cmso/v1/loopbacktest/optimize/schedule\r
-cmso.optimizer.status.url=http://localhost:8080/cmso/v1/loopbacktest/optimize/schedule\r
-cmso.optimizer.health.url=http://localhost:8080/cmso/v1/loopbacktest/optimize/schedule/health\r
+#cmso.optimizer.request.url=http://localhost:8080/cmso/v1/loopbacktest/optimize/schedule\r
+#cmso.optimizer.status.url=http://localhost:8080/cmso/v1/loopbacktest/optimize/schedule\r
+#cmso.optimizer.health.url=http://localhost:8080/cmso/v1/loopbacktest/optimize/schedule/health\r
\r
## Local optimizer service\r
-#cmso.optimizer.request.url=http://127.0.0.1:7997/optimizer/v1/optimize/schedule\r
-#cmso.optimizer.status.url=http://127.0.0.1:7997/optimizer/v1/optimize/schedule\r
-#cmso.optimizer.health.url=http://127.0.0.1:7997/optimizer/v1/health?checkInterfaces=true\r
+cmso.optimizer.request.url=http://127.0.0.1:7997/optimizer/v1/optimize/schedule\r
+cmso.optimizer.status.url=http://127.0.0.1:7997/optimizer/v1/optimize/schedule\r
+cmso.optimizer.health.url=http://127.0.0.1:7997/optimizer/v1/health?checkInterfaces=true\r
/*\r
* Copyright © 2017-2018 AT&T Intellectual Property.\r
* Modifications Copyright © 2018 IBM.\r
- * \r
+ *\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
* You may obtain a copy of the License at\r
- * \r
+ *\r
* http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
+ *\r
* Unless required by applicable law or agreed to in writing, software\r
* distributed under the License is distributed on an "AS IS" BASIS,\r
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
* See the License for the specific language governing permissions and\r
* limitations under the License.\r
- * \r
- * \r
+ *\r
+ *\r
* Unless otherwise specified, all documentation contained herein is licensed\r
* under the Creative Commons License, Attribution 4.0 Intl. (the "License");\r
* you may not use this documentation except in compliance with the License.\r
* You may obtain a copy of the License at\r
- * \r
+ *\r
* https://creativecommons.org/licenses/by/4.0/\r
- * \r
+ *\r
* Unless required by applicable law or agreed to in writing, documentation\r
* distributed under the License is distributed on an "AS IS" BASIS,\r
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ " left outer join APPROVAL_TYPES at on sa.approval_types_uuid = at.uuid ");\r
sql.append(where);\r
sql.append(" order by uuid ");\r
- if (limit > 0)\r
+ if (limit > 0) {\r
sql.append("LIMIT " + limit);\r
+ }\r
\r
- Query q = manager.createNativeQuery(sql.toString(), ChangeManagementDetail.class);\r
- List<ChangeManagementDetail> list = q.getResultList();\r
+ Query query = manager.createNativeQuery(sql.toString(), ChangeManagementDetail.class);\r
+ @SuppressWarnings("unchecked")\r
+ List<ChangeManagementDetail> list = query.getResultList();\r
return list;\r
}\r
}\r
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);
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);
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) {
optElement.setElementData(element.getElementData());
optElement.setElementId(element.getElementId());
optElement.setGroupId(element.getGroupId());
- list.add(optElement );
+ list.add(optElement);
}
return list;
}
/**
* Health check.
+ *
* @return
*/
public HealthCheckComponent healthCheck() {
private static EELFLogger log = EELFManager.getInstance().getLogger(OptimizerQuartzJob.class);\r
private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();\r
private static EELFLogger errors = EELFManager.getInstance().getErrorLogger();\r
- private static EELFLogger metrics = EELFManager.getInstance().getMetricsLogger();\r
\r
@Autowired\r
- ScheduleDAO scheduleDAO;\r
+ ScheduleDAO scheduleDao;\r
\r
@Autowired\r
PropertiesManagement pm;\r
// return;\r
\r
try {\r
- // This job will look at the schedules waiting to go to Optimizer or waiting on response from optimizer\r
+ // This job will look at the schedules waiting to go to Optimizer or waiting on response from\r
+ // optimizer\r
// (PendingSchedule, PendingOptimizer),\r
// schedule the request and update the status to PendingSchedule\r
// and update the state to OptimizationInProgress\r
- List<Schedule> schedules = scheduleDAO.findByDomainStatus(DomainsEnum.ChangeManagement.toString(),\r
- CMSStatusEnum.PendingSchedule.toString());\r
+ List<Schedule> schedules = scheduleDao.findByDomainStatus(DomainsEnum.ChangeManagement.toString(),\r
+ CMSStatusEnum.PendingSchedule.toString());\r
for (Schedule s : schedules) {\r
scheduleOptimization(s);\r
}\r
- List<Schedule> inProgressSchedules = scheduleDAO.findByDomainStatus(DomainsEnum.ChangeManagement.toString(),\r
- CMSStatusEnum.OptimizationInProgress.toString());\r
- for (Schedule s : inProgressSchedules)\r
- {\r
- scheduleOptimization(s);\r
+ List<Schedule> inProgressSchedules = scheduleDao.findByDomainStatus(DomainsEnum.ChangeManagement.toString(),\r
+ CMSStatusEnum.OptimizationInProgress.toString());\r
+ for (Schedule s : inProgressSchedules) {\r
+ scheduleOptimization(s);\r
}\r
\r
} catch (Exception e) {\r
default: {\r
\r
throw new SchedulerException(\r
- "Invalid return from dispach service: " + url + " : " + response.toString());\r
+ "Invalid return from dispach service: " + url + " : " + response.toString());\r
}\r
}\r
} catch (Exception e) {\r
}\r
\r
/**\r
- * According to the documentation I read, Quartz would queue a job without\r
- * waiting for the completion of the job with @DisallowConcurrentExecution to\r
- * complete so that there would be a backlog of triggers to process\r
+ * According to the documentation I read, Quartz would queue a job without waiting for the\r
+ * completion of the job with @DisallowConcurrentExecution to complete so that there would be a\r
+ * backlog of triggers to process\r
*\r
- * This was designed to spin though these stale triggers. When this didn't work,\r
- * I discovered that the behavior is that Quartz will wait for the appropriate\r
- * interval after @DisallowConcurrentExecution jobs complete.\r
+ * This was designed to spin though these stale triggers. When this didn't work, I discovered that\r
+ * the behavior is that Quartz will wait for the appropriate interval\r
+ * after @DisallowConcurrentExecution jobs complete.\r
*\r
* I tested by adding a sleep for an interval > the trigger interval\r
*\r
- * QUartz appears to do what makes sense. Leaving this here in case issues\r
- * arise...\r
+ * QUartz appears to do what makes sense. Leaving this here in case issues arise...\r
*\r
*/\r
@SuppressWarnings("unused")\r