blob: f37125424e83191f5caa7a1224bc02c231f488f9 [file] [log] [blame]
jaegonkim6a7b5242018-09-12 23:09:42 +09001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.workflow.api;
17
18import com.google.common.base.MoreObjects;
19
jaegonkim566991c2020-03-08 08:52:23 +090020import java.util.UUID;
21
jaegonkim6a7b5242018-09-12 23:09:42 +090022/**
23 * WorkflowContext for system workflow.
24 */
25public class SystemWorkflowContext extends DefaultWorkflowContext {
26
27 /**
28 * Timestamp when this system workflow context was created.
29 */
30 private final long timestamp;
31
32 /**
jaegonkim566991c2020-03-08 08:52:23 +090033 * UUID of this system workflow context.
34 */
35 private final String uuid;
36
37 /**
jaegonkim6a7b5242018-09-12 23:09:42 +090038 * Distributor string for designating which onos node executes this workflow context with work partition.
39 */
40 private String distributor;
41
42 /**
43 * The constructor of SystemWorkflowContext.
jaegonkime0f45b52018-10-09 20:23:26 +090044 * @param builder builder of SystemWorkflowContext
jaegonkim6a7b5242018-09-12 23:09:42 +090045 */
jaegonkime0f45b52018-10-09 20:23:26 +090046 public SystemWorkflowContext(Builder builder) {
47 super(builder);
jaegonkim6a7b5242018-09-12 23:09:42 +090048 timestamp = System.currentTimeMillis();
jaegonkim566991c2020-03-08 08:52:23 +090049 uuid = UUID.randomUUID().toString();
jaegonkim6a7b5242018-09-12 23:09:42 +090050 //initial distributor(It can be changed)
51 distributor = name();
52 }
53
54 @Override
55 public String distributor() {
56 return distributor;
57 }
58
59 /**
60 * Sets distributor string of this workflow context.
61 * @param distributor distributor string
62 */
63 public void setDistributor(String distributor) {
64 this.distributor = distributor;
65 }
66
67 @Override
68 public String name() {
69 return workflowId().toString()
jaegonkim566991c2020-03-08 08:52:23 +090070 + ":" + uuid
jaegonkim6a7b5242018-09-12 23:09:42 +090071 + "@" + workplaceName();
72 }
73
74 @Override
75 public String toString() {
76 return MoreObjects.toStringHelper(getClass())
77 .add("name", name())
78 .add("triggernext", triggerNext())
79 .add("data", data())
80 .add("current", current())
81 .add("state", state())
82 .add("cause", cause())
83 .toString();
84 }
jaegonkime0f45b52018-10-09 20:23:26 +090085
86 /**
87 * Gets systemBuilder instance.
88 * @return systemBuilder instance
89 */
90 public static final Builder systemBuilder() {
91 return new Builder();
92 }
93
94 /**
95 * Builder for system workflow context.
96 */
97 public static class Builder extends DefaultWorkflowContext.Builder {
98
99 /**
100 * Builds system workflow context.
101 * @return instance of default workflow context.
102 */
103 public SystemWorkflowContext build() {
104 return new SystemWorkflowContext(this);
105 }
106 }
107
jaegonkim6a7b5242018-09-12 23:09:42 +0900108}