c4ced5ef6c383aa178cddf0e92167485c0e88005
[clamp.git] / src / main / java / org / onap / clamp / clds / util / drawing / ClampGraphBuilder.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 Nokia. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * Modifications copyright (c) 2019 AT&T
21  * ===================================================================
22  *
23  */
24
25 package org.onap.clamp.clds.util.drawing;
26
27 import java.util.ArrayList;
28 import java.util.List;
29 import java.util.Objects;
30
31 import org.onap.clamp.clds.sdc.controller.installer.MicroService;
32
33 public class ClampGraphBuilder {
34     private String policy;
35     private String collector;
36     private List<MicroService> microServices = new ArrayList<>();
37     private final Painter painter;
38
39     public ClampGraphBuilder(Painter painter) {
40         this.painter = painter;
41     }
42
43     public ClampGraphBuilder collector(String collector) {
44         this.collector = collector;
45         return this;
46     }
47
48     public ClampGraphBuilder policy(String policy) {
49         this.policy = policy;
50         return this;
51     }
52
53     public ClampGraphBuilder addMicroService(MicroService ms) {
54         microServices.add(ms);
55         return this;
56     }
57
58     public ClampGraphBuilder addAllMicroServices(List<MicroService> msList) {
59         microServices.addAll(msList);
60         return this;
61     }
62
63     public ClampGraph build() {
64         if (microServices.isEmpty()) {
65             throw new InvalidStateException("At least one microservice is required");
66         }
67         if (Objects.isNull(policy) || policy.trim().isEmpty()) {
68             throw new InvalidStateException("Policy element must be present");
69         }
70         return new ClampGraph(painter.doPaint(collector, microServices, policy));
71     }
72 }