1 /*******************************************************************************
2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.database.types;
20 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
21 import java.time.ZonedDateTime;
22 import java.util.ArrayList;
23 import java.util.List;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.EsObject;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.MaintenanceModeG;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.maintenance.mode.g.Filter;
27 import org.opendaylight.yangtools.yang.binding.DataContainer;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * Database record entry for maintenance mode, as specified. Used for read operations Structure: _id
33 * : Contains the mountpoint name, must be specified before read. startTime: String representing
34 * Java LocalDateTime with absolute UTC Time endTime: String representing Java LocalDateTime with
35 * absolute UTC Time JSON Structure example { "_index": "mwtn_v1", "_type": "maintenancemode",
36 * "_id": "LumpiWave-Z3", "_score": 1, "_source": { "node": "LumpiWave-Z3", "filter": [ {
37 * "definition": { "object-id-ref": "", "problem": "" }, "description": "", "start":
38 * "2018-01-01T10:00+00:00", "end": "2018-10-10T10:00+00:00" }, { "definition": { "object-id-ref":
39 * "network-element", "problem": "power-alarm" }, "description": "", "start":
40 * "2018-01-01T10:00+00:00", "end": "2018-10-10T10:00+00:00" } ] } },
42 * Two filters for all element and one for network-element power-alarm
45 public class EsMaintenanceMode extends EsObject implements MaintenanceModeG {
47 @SuppressWarnings("unused")
48 private static final Logger LOG = LoggerFactory.getLogger(EsMaintenanceMode.class);
50 public static final String ESDATATYPENAME = "maintenancemode";
52 private static final EsMaintenanceMode NOT_IN_MAINTENANCE = new EsMaintenanceMode("notinmaintenance");
56 @JsonDeserialize(as = ArrayList.class)
57 private List<EsMaintenanceFilter> filter;
59 private boolean active;
62 public EsMaintenanceMode() {
64 this.filter = new ArrayList<>();
67 public EsMaintenanceMode(String mountpoint) {
69 this.setEsId(mountpoint);
70 this.node = mountpoint;
73 public EsMaintenanceMode(MaintenanceModeG maintenanceModeG) {
74 this.setEsId(maintenanceModeG.getMountpointName());
75 this.node = maintenanceModeG.getNodeName();
76 List<Filter> filters = maintenanceModeG.getFilter();
78 for (Filter filterElement : filters) {
79 this.filter.add(new EsMaintenanceFilter(filterElement));
85 public String getNode() {
89 public void setNode(String node) {
93 public List<EsMaintenanceFilter> getFilter2() {
97 public void setActive(boolean a) {
102 * Replace list with new one.
104 * @param filterList new filter list
106 public void setFilter(List<EsMaintenanceFilter> filterList) {
107 this.filter = filterList;
111 * Add one filter to internal list
113 * @param pFilter the Filter
115 public void addFilter(EsMaintenanceFilter pFilter) {
116 this.filter.add(pFilter);
120 * Verify maintenance status
122 * @param objectIdRef NETCONF object id
123 * @param problem name that was provided
124 * @param now time to verify with
125 * @return true if in maintenance status
127 public boolean isONFObjectInMaintenance(String objectIdRef, String problem, ZonedDateTime now) {
132 if (this != NOT_IN_MAINTENANCE) {
133 for (EsMaintenanceFilter oneFilter : filter) {
134 if (oneFilter.isInMaintenance(objectIdRef, problem, now)) {
144 public boolean isONFObjectInMaintenance(String objectIdRef, String problem) {
145 return isONFObjectInMaintenance(objectIdRef, problem, EsMaintenanceFilter.getNow());
149 public String toString() {
150 return "EsMaintenanceMode [node=" + node + ", filter=" + filter + ", active=" + active + "]";
153 public static EsMaintenanceMode getNotInMaintenance() {
154 return NOT_IN_MAINTENANCE;
157 /*---------------------------------------------
158 * yang tools related functions
162 public Class<? extends DataContainer> getImplementedInterface() {
163 return MaintenanceModeG.class;
167 public String getMountpointName() {
168 return this.getEsId();
172 public String getNodeName() {
177 public List<Filter> getFilter() {
178 return filter.isEmpty() ? null : new ArrayList<>(filter);