2 * ============LICENSE_START==============================================
3 * Copyright (c) 2019 AT&T Intellectual Property.
4 * =======================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain a
7 * copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 * ============LICENSE_END=================================================
20 package org.onap.optf.cmso.optimizer.availability.timewindows;
22 import java.time.Instant;
23 import java.util.ArrayList;
24 import java.util.Date;
25 import java.util.List;
26 import org.onap.observations.Observation;
27 import org.onap.optf.cmso.optimizer.availability.policies.model.AllowedPeriodicTime;
28 import org.onap.optf.cmso.optimizer.availability.policies.model.TimeLimitAndVerticalTopology;
29 import org.onap.optf.cmso.optimizer.availability.policies.model.TimeRange;
30 import org.onap.optf.cmso.optimizer.common.LogMessages;
31 import org.onap.optf.cmso.optimizer.service.rs.models.ChangeWindow;
33 public class RecurringWindows {
35 public static List<ChangeWindow> getAvailabilityWindowsForPolicies(List<TimeLimitAndVerticalTopology> policies,
36 ChangeWindow changeWindow) {
37 List<ChangeWindow> availableList = new ArrayList<>();
38 for (TimeLimitAndVerticalTopology policy : policies) {
39 if (policy.getTimeSchedule() != null && policy.getTimeSchedule().getAllowedPeriodicTime() != null) {
40 for (AllowedPeriodicTime available : policy.getTimeSchedule().getAllowedPeriodicTime()) {
41 getAvailableWindowsForApt(available, changeWindow, availableList);
50 // "RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR",
51 private static void getAvailableWindowsForApt(AllowedPeriodicTime available, ChangeWindow changeWindow,
52 List<ChangeWindow> availableList) {
54 if (available.getDay() != null)
56 switch (available.getDay())
60 getAvailableWindowsForAptDay(available, changeWindow, availableList);
66 Observation.report(LogMessages.UNSUPPORTED_PERIODIC_TIME, available.toString());
69 // "RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR",
70 private static void getAvailableWindowsForAptDay(AllowedPeriodicTime available, ChangeWindow changeWindow,
71 List<ChangeWindow> availableList) {
74 List<TimeRange> ranges = available.getTimeRange();
75 if (ranges.size() == 0)
77 TimeRange range = new TimeRange();
78 range.setStart_time("00:00:00+00:00");
79 range.setStart_time("23:59:59+00:00");
82 String rrule = available.getDay().getRrule();
83 for (TimeRange range : ranges)
86 Date cwStartDate =changeWindow.getStartTime();
87 Date cwEndDate =changeWindow.getEndTime();
89 Instant cwStartInstant = Instant.ofEpochMilli(cwStartDate.getTime());
90 Instant cwEndInstant = Instant.ofEpochMilli(cwEndDate.getTime());
91 Instant startInstant = Instant.parse(range.getStart_time());
92 Instant endInstant = Instant.parse(range.getEnd_time());
93 if (cwStartInstant.isAfter(startInstant))
95 // We expect this since startInstant has no date (1/1/1970)
104 Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());