f9704ff9848b4f380eefbab260646a9effb74453
[optf/cmso.git] /
1 /*
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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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=================================================
17  *
18  */
19
20 package org.onap.optf.cmso.optimizer.availability.timewindows;
21
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;
32
33 public class RecurringWindows {
34
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);
42                 }
43             }
44         }
45         return availableList;
46
47     }
48
49
50     // "RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR",
51     private static void getAvailableWindowsForApt(AllowedPeriodicTime available, ChangeWindow changeWindow,
52                     List<ChangeWindow> availableList) {
53
54         if (available.getDay() != null)
55         {
56             switch (available.getDay())
57             {
58                 case weekday:
59                 case weekend:
60                     getAvailableWindowsForAptDay(available, changeWindow, availableList);
61                     return;
62                 default:
63
64             }
65         }
66         Observation.report(LogMessages.UNSUPPORTED_PERIODIC_TIME, available.toString());
67
68     }
69     // "RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR",
70     private static void getAvailableWindowsForAptDay(AllowedPeriodicTime available, ChangeWindow changeWindow,
71                     List<ChangeWindow> availableList) {
72         try
73         {
74             List<TimeRange> ranges = available.getTimeRange();
75             if (ranges.size() == 0)
76             {
77                 TimeRange range = new TimeRange();
78                 range.setStart_time("00:00:00+00:00");
79                 range.setStart_time("23:59:59+00:00");
80                 ranges.add(range);
81             }
82             String rrule = available.getDay().getRrule();
83             for (TimeRange range : ranges)
84             {
85
86                 Date cwStartDate =changeWindow.getStartTime();
87                 Date cwEndDate =changeWindow.getEndTime();
88
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))
94                 {
95                     // We expect this since startInstant has no  date (1/1/1970)
96                     //
97                 }
98
99
100             }
101         }
102         catch (Exception e)
103         {
104             Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
105         }
106     }
107
108 }