78fb479170bc24858d587be97c736ccb184a0dac
[policy/gui.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020-2021 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 INFINITY_TIME_TO_LIVE = -1;
42
43     // Base URI the HTTP server will listen on
44     private static final String DEFAULT_SERVER_URI_ROOT = "http://0.0.0.0:";
45     private static final String DEFAULT_REST_PATH = "papservices/*";
46     private static final String DEFAULT_CONTEXT_PATH = "/";
47     private static final String SERVER_HOST = "0.0.0.0";
48     private static final int DEFAULT_REST_PORT = 17999;
49     // Package that will field REST requests
50     private static final String DEFAULT_REST_PACKAGE = "org.onap.policy.gui.pdp.monitoring.rest";
51
52     // The services parameters
53     private boolean helpSet = false;
54
55     @Min(1024)
56     @Max(65534)
57     private int port = DEFAULT_REST_PORT;
58
59     @Min(-1)
60     private long timeToLive = INFINITY_TIME_TO_LIVE;
61
62     /**
63      * Validate the parameters.
64      *
65      * @return the result of the validation
66      */
67     public ValidationResult validate() {
68         return new BeanValidator().validateTop(PdpMonitoringServerParameters.class.getSimpleName(), this);
69     }
70
71     public URI getBaseUri() {
72         return URI.create(DEFAULT_SERVER_URI_ROOT + port + "/" + DEFAULT_REST_PATH);
73     }
74
75     public String getRestPackage() {
76         return DEFAULT_REST_PACKAGE;
77     }
78
79     public String getContextPath() {
80         return DEFAULT_CONTEXT_PATH;
81     }
82
83     public String getServerHost() {
84         return SERVER_HOST;
85     }
86
87     public String getDefaultRestPath() {
88         return "/" + DEFAULT_REST_PATH;
89     }
90 }