614d47d74db381e9bcf5bf2707012c493f278351
[policy/gui.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.gui.pdp.monitoring;
22
23 import java.net.URI;
24 import lombok.Getter;
25 import lombok.Setter;
26 import lombok.ToString;
27 import org.onap.policy.common.parameters.BeanValidator;
28 import org.onap.policy.common.parameters.ValidationResult;
29 import org.onap.policy.common.parameters.annotations.Max;
30 import org.onap.policy.common.parameters.annotations.Min;
31
32 /**
33  * This class reads and handles command line parameters to the Pdp Monitoring services.
34  *
35  * @author Yehui Wang (yehui.wang@est.tech)
36  */
37 @ToString
38 @Getter
39 @Setter
40 public class PdpMonitoringServerParameters {
41     public static final int DEFAULT_PORT = 18999;
42     public static final int INFINITY_TIME_TO_LIVE = -1;
43
44     // Base URI the HTTP server will listen on
45     private static final String DEFAULT_SERVER_URI_ROOT = "http://0.0.0.0:";
46     private static final String DEFAULT_REST_PATH = "/papservices/*";
47     private static final String DEFAULT_CONTEXT_PATH = "/";
48     private static final String SERVER_HOST = "0.0.0.0";
49     private static final int DEFAULT_REST_PORT = 17999;
50     // Package that will field REST requests
51     private static final String DEFAULT_REST_PACKAGE = "org.onap.policy.gui.pdp.monitoring.rest";
52
53     // The services parameters
54     private boolean helpSet = false;
55
56     @Min(1024)
57     @Max(65534)
58     private int port = DEFAULT_PORT;
59
60     @Min(-1)
61     private long timeToLive = INFINITY_TIME_TO_LIVE;
62
63     /**
64      * Validate the parameters.
65      *
66      * @return the result of the validation
67      */
68     public ValidationResult validate() {
69         return new BeanValidator().validateTop(PdpMonitoringServerParameters.class.getSimpleName(), this);
70     }
71
72     public URI getBaseUri() {
73         return URI.create(DEFAULT_SERVER_URI_ROOT + port + DEFAULT_REST_PATH);
74     }
75
76     public String getRestPackage() {
77         return DEFAULT_REST_PACKAGE;
78     }
79
80     public String getContextPath() {
81         return DEFAULT_CONTEXT_PATH;
82     }
83
84     public String getServerHost() {
85         return SERVER_HOST;
86     }
87
88     public String getDefaultRestPath() {
89         return DEFAULT_REST_PATH;
90     }
91
92     public int getDefaultRestPort() {
93         return DEFAULT_REST_PORT;
94     }
95 }