[APPC-44] revert license line ending changes
[appc.git] / appc-lifecycle-management / state-machine-lib / src / main / java / org / openecomp / appc / statemachine / impl / readers / AppcOamMetaDataReader.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.openecomp.appc.statemachine.impl.readers;
26
27 import org.openecomp.appc.statemachine.StateMetaDataReader;
28 import org.openecomp.appc.statemachine.objects.Event;
29 import org.openecomp.appc.statemachine.objects.State;
30 import org.openecomp.appc.statemachine.objects.StateMachineMetadata;
31
32 public class AppcOamMetaDataReader implements StateMetaDataReader {
33
34     public enum AppcOperation {
35         MaintenanceMode,
36         Restart,
37         Start,
38         Stop
39     }
40
41     @Override
42     public StateMachineMetadata readMetadata() {
43         State NOT_INSTANTIATED = new State(AppcOamStates.NotInstantiated.toString());
44         State INSTANTIATED = new State(AppcOamStates.Instantiated.toString());
45         State RESTARTING = new State(AppcOamStates.Restarting.toString());
46         State STARTING = new State(AppcOamStates.Starting.toString());
47         State STARTED = new State(AppcOamStates.Started.toString());
48         State ENTERING_MAINTENANCE_MODE = new State(AppcOamStates.EnteringMaintenanceMode.toString());
49         State MAINTENANCE_MODE = new State(AppcOamStates.MaintenanceMode.toString());
50         State ERROR = new State(AppcOamStates.Error.toString());
51         State UNKNOWN = new State(AppcOamStates.Unknown.toString());
52         State STOPPING = new State(AppcOamStates.Stopping.toString());
53         State STOPPED = new State(AppcOamStates.Stopped.toString());
54
55         Event START = new Event(AppcOperation.Start.toString());
56         Event STOP = new Event(AppcOperation.Stop.toString());
57         Event MAINTENANCE_MODE_EVENT = new Event(AppcOperation.MaintenanceMode.toString());
58         Event RESTART = new Event(AppcOperation.Restart.toString());
59
60         StateMachineMetadata.StateMachineMetadataBuilder builder = new StateMachineMetadata
61                 .StateMachineMetadataBuilder();
62
63         builder = builder.addState(NOT_INSTANTIATED);
64         builder = builder.addState(INSTANTIATED);
65         builder = builder.addState(STARTING);
66         builder = builder.addState(STARTED);
67         builder = builder.addState(ERROR);
68         builder = builder.addState(UNKNOWN);
69         builder = builder.addState(STOPPING);
70         builder = builder.addState(STOPPED);
71         builder = builder.addState(ENTERING_MAINTENANCE_MODE);
72         builder = builder.addState(MAINTENANCE_MODE);
73         builder = builder.addState(RESTARTING);
74
75         builder = builder.addEvent(START);
76         builder = builder.addEvent(STOP);
77         builder = builder.addEvent(RESTART);
78         builder = builder.addEvent(MAINTENANCE_MODE_EVENT);
79
80         /*
81          *  for addTransition:
82          *  param 1: current state; param 2: received command/request; param 3: new transition state
83          */
84         // start
85         builder = builder.addTransition(STOPPED,                   START, STARTING);
86         builder = builder.addTransition(MAINTENANCE_MODE,          START, STARTING);
87         builder = builder.addTransition(ERROR,                     START, STARTING);
88         // stop
89         builder = builder.addTransition(STARTED,                   STOP, STOPPING);
90         builder = builder.addTransition(STARTING,                  STOP, STOPPING);
91         builder = builder.addTransition(ENTERING_MAINTENANCE_MODE, STOP, STOPPING);
92         builder = builder.addTransition(MAINTENANCE_MODE,          STOP, STOPPING);
93         builder = builder.addTransition(ERROR,                     STOP, STOPPING);
94         // maintenance mode
95         builder = builder.addTransition(
96                 STARTED, MAINTENANCE_MODE_EVENT, ENTERING_MAINTENANCE_MODE);
97         // restart
98         builder = builder.addTransition(STOPPED,                   RESTART, RESTARTING);
99         builder = builder.addTransition(STARTING,                  RESTART, RESTARTING);
100         builder = builder.addTransition(STARTED,                   RESTART, RESTARTING);
101         builder = builder.addTransition(ENTERING_MAINTENANCE_MODE, RESTART, RESTARTING);
102         builder = builder.addTransition(MAINTENANCE_MODE,          RESTART, RESTARTING);
103         builder = builder.addTransition(ERROR,                     RESTART, RESTARTING);
104
105         return builder.build();
106     }
107 }