aboutsummaryrefslogtreecommitdiffstats
path: root/cmso-optimizer/src/main/java/org
diff options
context:
space:
mode:
authorJerry Flood <jflood@att.com>2019-03-28 16:44:34 -0400
committerJerry Flood <jflood@att.com>2019-03-28 16:44:57 -0400
commitb635eba9d34b51f37670b4dc7ca1274760020c43 (patch)
treecb7bb490df6d080c9edfa17bdbc9a60a20e27d18 /cmso-optimizer/src/main/java/org
parentfe8c1df09a3c74321831b40f6f953016d746aa61 (diff)
Added policy model with local policies
Issue-ID: OPTFRA-458 Change-Id: If8fedf34a0f41ae7936500f08a05259a27af6270 Signed-off-by: Jerry Flood <jflood@att.com>
Diffstat (limited to 'cmso-optimizer/src/main/java/org')
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/PolicyManager.java116
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/AllowedPeriodicTime.java65
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/Policy.java135
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/PolicyScope.java69
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/TimeLimitAndVerticalTopology.java115
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/TimeRange.java48
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/TimeSchedule.java51
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/timewindows/RecurringWindows.java108
8 files changed, 707 insertions, 0 deletions
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/PolicyManager.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/PolicyManager.java
new file mode 100644
index 0000000..d6ae196
--- /dev/null
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/PolicyManager.java
@@ -0,0 +1,116 @@
+/*
+ * ============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.policies;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import org.onap.observations.Observation;
+import org.onap.optf.cmso.optimizer.availability.policies.model.Policy;
+import org.onap.optf.cmso.optimizer.availability.policies.model.TimeLimitAndVerticalTopology;
+import org.onap.optf.cmso.optimizer.common.LogMessages;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+
+@Component
+public class PolicyManager {
+
+ @Autowired
+ Environment env;
+
+ public TimeLimitAndVerticalTopology getTimeLimitAndVerticalTopologyByName(String name) {
+ Policy policy = getPolicyForName(name);
+ TimeLimitAndVerticalTopology returnPolicy = null;
+ if (policy != null) {
+ ObjectMapper om = new ObjectMapper();
+ try
+ {
+ returnPolicy = om.convertValue(policy.getContent(), TimeLimitAndVerticalTopology.class);
+ }
+ catch (Exception e)
+ {
+ Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ }
+ }
+ return returnPolicy;
+ }
+
+
+ public Policy getPolicyForName(String name) {
+ Policy policy = null;
+ try {
+ return getLocalPolicyForName(name);
+ } catch (Exception e) {
+ Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ }
+ return policy;
+ }
+
+ public Policy getLocalPolicyForName(String name) {
+ String policyFolder = env.getProperty("cmso.local.policy.folder", "data/policies");
+ Policy policy = null;
+ try {
+ if (!name.endsWith(".json")) {
+ name += ".json";
+ }
+ Path path = Paths.get(policyFolder, name);
+ ObjectMapper om = new ObjectMapper();
+ policy = om.readValue(path.toFile(), Policy.class);
+ } catch (Exception e) {
+ Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ }
+ return policy;
+ }
+
+ public List<Policy> getSupportedPolicies() {
+ List<Policy> policies = new ArrayList<>();
+ try {
+ return getLocalSupportedPolicies();
+ } catch (Exception e) {
+ Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ }
+ return policies;
+ }
+
+ public List<Policy> getLocalSupportedPolicies() {
+ String policyFolder = env.getProperty("cmso.local.policy.folder", "data/policies");
+ List<Policy> policies = new ArrayList<>();
+ try {
+ Path path = Paths.get(policyFolder);
+ for (File file : path.toFile().listFiles()) {
+ if (file.isFile()) {
+ Policy policy = getLocalPolicyForName(file.getName());
+ if (policy != null) {
+ policies.add(policy);
+ }
+ }
+
+ }
+ } catch (Exception e) {
+ Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ }
+ return policies;
+ }
+
+}
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/AllowedPeriodicTime.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/AllowedPeriodicTime.java
new file mode 100644
index 0000000..4bc0f71
--- /dev/null
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/AllowedPeriodicTime.java
@@ -0,0 +1,65 @@
+/*
+ * ============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.policies.model;
+
+import java.util.List;
+
+/*
+
+{
+ "day": "weekday",
+ "timeRange": [
+ {
+ "start_time": "00:00:00+00:00",
+ "end_time": "06:00:00+00:00"
+ }
+ ]
+}
+
+ */
+public class AllowedPeriodicTime {
+
+ public enum Day
+ {
+ weekday("RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR"),
+ weekend("RRULE:FREQ=WEEKLY;BYDAY=SA,SU"),
+ ;
+ private String rrule;
+ private Day(String rrule) {this.rrule = rrule;}
+ public String getRrule() {return rrule;}
+
+ }
+
+ private Day day;
+ private List<TimeRange> timeRange;
+ public Day getDay() {
+ return day;
+ }
+ public void setDay(Day day) {
+ this.day = day;
+ }
+ public List<TimeRange> getTimeRange() {
+ return timeRange;
+ }
+ public void setTimeRange(List<TimeRange> timeRange) {
+ this.timeRange = timeRange;
+ }
+
+}
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/Policy.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/Policy.java
new file mode 100644
index 0000000..50acd9b
--- /dev/null
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/Policy.java
@@ -0,0 +1,135 @@
+/*
+ * ============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.policies.model;
+
+/*
+{
+ "service": "TimeLimitAndVerticalTopology",
+ "policyName": "CMSO.Weekday_00_06",
+ "description": "dev instance",
+ "templateVersion": "Dublin",
+ "version": "0001",
+ "priority": "4",
+ "riskType": "test",
+ "riskLevel": "3",
+ "guard": "False",
+ "content": {
+ "serviceType": "networkOnDemand",
+ "identity": "vnf_upgrade_policy",
+ "policyScope": {
+ "serviceType": ["networkOnDemand"],
+ "aicZone": [
+ " "
+ ],
+ "entityType": ["vnf"]
+ },
+ "timeSchedule": {
+ "allowedPeriodicTime": [
+ {
+ "day": "weekday",
+ "timeRange": [
+ {
+ "start_time": "00:00:00+00:00",
+ "end_time": "06:00:00+00:00"
+ }
+ ]
+ }
+ ]
+ },
+ "nodeType": ["vnf"],
+ "type": "timeLimitAndVerticalTopology",
+ "conflictScope": "vnf_pserver"
+ }
+}
+ */
+public class Policy {
+
+ private String service;
+ private String policyName;
+ private String description;
+ private String templateVersion;
+ private String version;
+ private String priority;
+ private String riskType;
+ private String riskLevel;
+ private String guard;
+ private Object content;
+ public String getService() {
+ return service;
+ }
+ public void setService(String service) {
+ this.service = service;
+ }
+ public String getPolicyName() {
+ return policyName;
+ }
+ public void setPolicyName(String policyName) {
+ this.policyName = policyName;
+ }
+ public String getDescription() {
+ return description;
+ }
+ public void setDescription(String description) {
+ this.description = description;
+ }
+ public String getTemplateVersion() {
+ return templateVersion;
+ }
+ public void setTemplateVersion(String templateVersion) {
+ this.templateVersion = templateVersion;
+ }
+ public String getVersion() {
+ return version;
+ }
+ public void setVersion(String version) {
+ this.version = version;
+ }
+ public String getPriority() {
+ return priority;
+ }
+ public void setPriority(String priority) {
+ this.priority = priority;
+ }
+ public String getRiskType() {
+ return riskType;
+ }
+ public void setRiskType(String riskType) {
+ this.riskType = riskType;
+ }
+ public String getRiskLevel() {
+ return riskLevel;
+ }
+ public void setRiskLevel(String riskLevel) {
+ this.riskLevel = riskLevel;
+ }
+ public String getGuard() {
+ return guard;
+ }
+ public void setGuard(String guard) {
+ this.guard = guard;
+ }
+ public Object getContent() {
+ return content;
+ }
+ public void setContent(Object content) {
+ this.content = content;
+ }
+
+}
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/PolicyScope.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/PolicyScope.java
new file mode 100644
index 0000000..d569274
--- /dev/null
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/PolicyScope.java
@@ -0,0 +1,69 @@
+/*
+ * ============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.policies.model;
+
+import java.util.List;
+
+/*
+{
+ "serviceType": ["networkOnDemand"],
+ "aicZone": [
+ " "
+ ],
+ "entityType": ["vnf"]
+ */
+public class PolicyScope {
+
+ public enum ServiceType {
+ networkOnDemand
+ }
+ public enum EntityType {
+ vnf
+ }
+
+ private List<String> serviceType;
+ private List<String> aicZone;
+ private List<String> entityType;
+
+ public List<String> getServiceType() {
+ return serviceType;
+ }
+
+ public void setServiceType(List<String> serviceType) {
+ this.serviceType = serviceType;
+ }
+
+ public List<String> getAicZone() {
+ return aicZone;
+ }
+
+ public void setAicZone(List<String> aicZone) {
+ this.aicZone = aicZone;
+ }
+
+ public List<String> getEntityType() {
+ return entityType;
+ }
+
+ public void setEntityType(List<String> entityType) {
+ this.entityType = entityType;
+ }
+
+}
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/TimeLimitAndVerticalTopology.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/TimeLimitAndVerticalTopology.java
new file mode 100644
index 0000000..58846f4
--- /dev/null
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/TimeLimitAndVerticalTopology.java
@@ -0,0 +1,115 @@
+/*
+ * ============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.policies.model;
+
+import java.util.List;
+
+/*
+{
+ "serviceType": "networkOnDemand",
+ "identity": "vnf_upgrade_policy",
+ "policyScope": {
+ "serviceType": ["networkOnDemand"],
+ "aicZone": [
+ " "
+ ],
+ "entityType": ["vnf"]
+ },
+ "timeSchedule": {
+ "allowedPeriodicTime": [
+ {
+ "day": "weekday",
+ "timeRange": [
+ {
+ "start_time": "00:00:00+00:00",
+ "end_time": "06:00:00+00:00"
+ }
+ ]
+ }
+ ]
+ },
+ "nodeType": ["vnf"],
+ "type": "timeLimitAndVerticalTopology",
+ "conflictScope": "vnf_pserver"
+}
+ */
+
+public class TimeLimitAndVerticalTopology
+{
+
+ public enum ConflictScope {
+ timeLimitAndVerticalTopology,
+ }
+ public enum Type {
+ vnf_pserver,
+ }
+
+ private String serviceType;
+ private String identity;
+ private PolicyScope policyScope;
+ private TimeSchedule timeSchedule;
+ private List<String> nodeType;
+ private String type;
+ private String conflictScope;
+
+ public String getServiceType() {
+ return serviceType;
+ }
+ public void setServiceType(String serviceType) {
+ this.serviceType = serviceType;
+ }
+ public String getIdentity() {
+ return identity;
+ }
+ public void setIdentity(String identity) {
+ this.identity = identity;
+ }
+ public PolicyScope getPolicyScope() {
+ return policyScope;
+ }
+ public void setPolicyScope(PolicyScope policyScope) {
+ this.policyScope = policyScope;
+ }
+ public TimeSchedule getTimeSchedule() {
+ return timeSchedule;
+ }
+ public void setTimeSchedule(TimeSchedule timeSchedule) {
+ this.timeSchedule = timeSchedule;
+ }
+ public List<String> getNodeType() {
+ return nodeType;
+ }
+ public void setNodeType(List<String> nodeType) {
+ this.nodeType = nodeType;
+ }
+ public String getType() {
+ return type;
+ }
+ public void setType(String type) {
+ this.type = type;
+ }
+ public String getConflictScope() {
+ return conflictScope;
+ }
+ public void setConflictScope(String conflictScope) {
+ this.conflictScope = conflictScope;
+ }
+
+}
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/TimeRange.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/TimeRange.java
new file mode 100644
index 0000000..6b6ba0b
--- /dev/null
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/TimeRange.java
@@ -0,0 +1,48 @@
+/*
+ * ============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.policies.model;
+
+/*
+
+{
+ "start_time": "00:00:00+00:00",
+ "end_time": "06:00:00+00:00"
+}
+
+ */
+public class TimeRange
+{
+ private String start_time;
+ private String end_time;
+
+ public String getStart_time() {
+ return start_time;
+ }
+ public void setStart_time(String start_time) {
+ this.start_time = start_time;
+ }
+ public String getEnd_time() {
+ return end_time;
+ }
+ public void setEnd_time(String end_time) {
+ this.end_time = end_time;
+ }
+
+}
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/TimeSchedule.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/TimeSchedule.java
new file mode 100644
index 0000000..4d3db2d
--- /dev/null
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/policies/model/TimeSchedule.java
@@ -0,0 +1,51 @@
+/*
+ * ============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.policies.model;
+
+import java.util.List;
+
+/*
+{
+ "allowedPeriodicTime": [
+ {
+ "day": "weekday",
+ "timeRange": [
+ {
+ "start_time": "00:00:00+00:00",
+ "end_time": "06:00:00+00:00"
+ }
+ ]
+ }
+ ]
+}
+ */
+public class TimeSchedule {
+
+ private List<AllowedPeriodicTime> allowedPeriodicTime;
+
+ public List<AllowedPeriodicTime> getAllowedPeriodicTime() {
+ return allowedPeriodicTime;
+ }
+
+ public void setAllowedPeriodicTime(List<AllowedPeriodicTime> allowedPeriodicTime) {
+ this.allowedPeriodicTime = allowedPeriodicTime;
+ }
+
+}
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/timewindows/RecurringWindows.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/timewindows/RecurringWindows.java
new file mode 100644
index 0000000..f9704ff
--- /dev/null
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/timewindows/RecurringWindows.java
@@ -0,0 +1,108 @@
+/*
+ * ============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.onap.observations.Observation;
+import org.onap.optf.cmso.optimizer.availability.policies.model.AllowedPeriodicTime;
+import org.onap.optf.cmso.optimizer.availability.policies.model.TimeLimitAndVerticalTopology;
+import org.onap.optf.cmso.optimizer.availability.policies.model.TimeRange;
+import org.onap.optf.cmso.optimizer.common.LogMessages;
+import org.onap.optf.cmso.optimizer.service.rs.models.ChangeWindow;
+
+public class RecurringWindows {
+
+ public static List<ChangeWindow> getAvailabilityWindowsForPolicies(List<TimeLimitAndVerticalTopology> policies,
+ ChangeWindow changeWindow) {
+ List<ChangeWindow> availableList = new ArrayList<>();
+ for (TimeLimitAndVerticalTopology policy : policies) {
+ if (policy.getTimeSchedule() != null && policy.getTimeSchedule().getAllowedPeriodicTime() != null) {
+ for (AllowedPeriodicTime available : policy.getTimeSchedule().getAllowedPeriodicTime()) {
+ getAvailableWindowsForApt(available, changeWindow, availableList);
+ }
+ }
+ }
+ return availableList;
+
+ }
+
+
+ // "RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR",
+ private static void getAvailableWindowsForApt(AllowedPeriodicTime available, ChangeWindow changeWindow,
+ List<ChangeWindow> availableList) {
+
+ if (available.getDay() != null)
+ {
+ switch (available.getDay())
+ {
+ case weekday:
+ case weekend:
+ getAvailableWindowsForAptDay(available, changeWindow, availableList);
+ return;
+ default:
+
+ }
+ }
+ Observation.report(LogMessages.UNSUPPORTED_PERIODIC_TIME, available.toString());
+
+ }
+ // "RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR",
+ private static void getAvailableWindowsForAptDay(AllowedPeriodicTime available, ChangeWindow changeWindow,
+ List<ChangeWindow> availableList) {
+ try
+ {
+ List<TimeRange> ranges = available.getTimeRange();
+ if (ranges.size() == 0)
+ {
+ TimeRange range = new TimeRange();
+ range.setStart_time("00:00:00+00:00");
+ range.setStart_time("23:59:59+00:00");
+ ranges.add(range);
+ }
+ String rrule = available.getDay().getRrule();
+ for (TimeRange range : ranges)
+ {
+
+ Date cwStartDate =changeWindow.getStartTime();
+ Date cwEndDate =changeWindow.getEndTime();
+
+ Instant cwStartInstant = Instant.ofEpochMilli(cwStartDate.getTime());
+ Instant cwEndInstant = Instant.ofEpochMilli(cwEndDate.getTime());
+ Instant startInstant = Instant.parse(range.getStart_time());
+ Instant endInstant = Instant.parse(range.getEnd_time());
+ if (cwStartInstant.isAfter(startInstant))
+ {
+ // We expect this since startInstant has no date (1/1/1970)
+ //
+ }
+
+
+ }
+ }
+ catch (Exception e)
+ {
+ Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ }
+ }
+
+}