2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a 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 or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.ncmp.api.inventory;
23 import com.fasterxml.jackson.annotation.JsonInclude;
24 import com.fasterxml.jackson.annotation.JsonProperty;
25 import java.time.OffsetDateTime;
26 import java.time.format.DateTimeFormatter;
27 import lombok.Builder;
30 import lombok.NoArgsConstructor;
34 * State Model to store state corresponding to the Yang resource dmi-registry model.
39 @JsonInclude(JsonInclude.Include.NON_NULL)
40 public class CompositeState {
42 @JsonProperty("cm-handle-state")
43 private CmHandleState cmHandleState;
45 @JsonProperty("lock-reason")
46 private LockReason lockReason;
48 @JsonProperty("last-update-time")
49 private String lastUpdateTime;
51 @JsonProperty("data-sync-enabled")
52 private Boolean dataSyncEnabled;
54 @JsonProperty("datastores")
55 private DataStores dataStores;
58 * Date and Time in the format of yyyy-MM-dd'T'HH:mm:ss.SSSZ
60 private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter
61 .ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
65 * This will specify the latest lock reason for a specific cm handle. If a cm handle is in a state other than LOCKED
66 * it specifies the last lock reason.
67 * This can be used to track retry attempts as part of the lock details.
71 @JsonInclude(JsonInclude.Include.NON_NULL)
72 public static class LockReason {
74 @JsonProperty("reason")
75 private LockReasonCategory lockReasonCategory;
77 @JsonProperty("details")
78 private String details;
84 @JsonInclude(JsonInclude.Include.NON_NULL)
85 public static class DataStores {
87 @JsonProperty("operational")
88 private Operational operationalDataStore;
93 @JsonInclude(JsonInclude.Include.NON_NULL)
94 public static class Operational {
96 @JsonProperty("sync-state")
97 private DataStoreSyncState dataStoreSyncState;
99 @JsonProperty("last-sync-time")
100 private String lastSyncTime;
105 @JsonInclude(JsonInclude.Include.NON_NULL)
106 public static class Running {
108 @JsonProperty("sync-state")
109 private String syncState;
111 @JsonProperty("last-sync-time")
112 private String lastSyncTime;
116 * The date and time format used for the cm handle sync state.
118 * @return the date and time in the format of yyyy-MM-dd'T'HH:mm:ss.SSSZ
120 public static String nowInSyncTimeFormat() {
121 return dateTimeFormatter.format(OffsetDateTime.now());
125 * Sets the last updated date and time for the cm handle sync state.
127 public void setLastUpdateTimeNow() {
128 lastUpdateTime = CompositeState.nowInSyncTimeFormat();