Skip to content

Commit 0ada819

Browse files
authored
Merge pull request #14 from opensearch-project/update-rest-endpoint-names
Update REST resources to follow new OpenSearch naming convention
2 parents 67d4ab7 + ca460ff commit 0ada819

15 files changed

+442
-115
lines changed

src/main/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerClusterConfigAction.java

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import static java.util.Collections.unmodifiableList;
3131

3232
import java.io.IOException;
33+
import java.util.Collections;
3334
import java.util.List;
3435
import java.util.Map;
3536
import org.apache.logging.log4j.LogManager;
@@ -59,28 +60,69 @@ public class PerformanceAnalyzerClusterConfigAction extends BaseRestHandler {
5960
public static final String CURRENT = "currentPerformanceAnalyzerClusterState";
6061
public static final String BATCH_METRICS_RETENTION_PERIOD_MINUTES =
6162
"batchMetricsRetentionPeriodMinutes";
62-
public static final String PA_CLUSTER_CONFIG_PATH =
63-
"/_opendistro/_performanceanalyzer/cluster/config";
63+
public static final String ENABLED = "enabled";
64+
public static final String SHARDS_PER_COLLECTION = "shardsPerCollection";
65+
66+
public static final String PA_CLUSTER_CONFIG_PATH = RestConfig.PA_BASE_URI + "/cluster/config";
6467
public static final String RCA_CLUSTER_CONFIG_PATH =
65-
"/_opendistro/_performanceanalyzer/rca/cluster/config";
68+
RestConfig.PA_BASE_URI + "/rca/cluster/config";
6669
public static final String LOGGING_CLUSTER_CONFIG_PATH =
67-
"/_opendistro/_performanceanalyzer/logging/cluster/config";
70+
RestConfig.PA_BASE_URI + "/logging/cluster/config";
6871
public static final String BATCH_METRICS_CLUSTER_CONFIG_PATH =
69-
"/_opendistro/_performanceanalyzer/batch/cluster/config";
70-
public static final String ENABLED = "enabled";
71-
public static final String SHARDS_PER_COLLECTION = "shardsPerCollection";
72+
RestConfig.PA_BASE_URI + "/batch/cluster/config";
7273

73-
private static final List<Route> ROUTES =
74+
public static final String LEGACY_PA_CLUSTER_CONFIG_PATH =
75+
RestConfig.LEGACY_PA_BASE_URI + "/cluster/config";
76+
public static final String LEGACY_RCA_CLUSTER_CONFIG_PATH =
77+
RestConfig.LEGACY_PA_BASE_URI + "/rca/cluster/config";
78+
public static final String LEGACY_LOGGING_CLUSTER_CONFIG_PATH =
79+
RestConfig.LEGACY_PA_BASE_URI + "/logging/cluster/config";
80+
public static final String LEGACY_BATCH_METRICS_CLUSTER_CONFIG_PATH =
81+
RestConfig.LEGACY_PA_BASE_URI + "/batch/cluster/config";
82+
83+
private static final List<ReplacedRoute> REPLACED_ROUTES =
7484
unmodifiableList(
7585
asList(
76-
new Route(RestRequest.Method.GET, PA_CLUSTER_CONFIG_PATH),
77-
new Route(RestRequest.Method.POST, PA_CLUSTER_CONFIG_PATH),
78-
new Route(RestRequest.Method.GET, RCA_CLUSTER_CONFIG_PATH),
79-
new Route(RestRequest.Method.POST, RCA_CLUSTER_CONFIG_PATH),
80-
new Route(RestRequest.Method.GET, LOGGING_CLUSTER_CONFIG_PATH),
81-
new Route(RestRequest.Method.POST, LOGGING_CLUSTER_CONFIG_PATH),
82-
new Route(RestRequest.Method.GET, BATCH_METRICS_CLUSTER_CONFIG_PATH),
83-
new Route(RestRequest.Method.POST, BATCH_METRICS_CLUSTER_CONFIG_PATH)));
86+
new ReplacedRoute(
87+
RestRequest.Method.GET,
88+
PA_CLUSTER_CONFIG_PATH,
89+
RestRequest.Method.GET,
90+
LEGACY_PA_CLUSTER_CONFIG_PATH),
91+
new ReplacedRoute(
92+
RestRequest.Method.POST,
93+
PA_CLUSTER_CONFIG_PATH,
94+
RestRequest.Method.POST,
95+
LEGACY_PA_CLUSTER_CONFIG_PATH),
96+
new ReplacedRoute(
97+
RestRequest.Method.GET,
98+
RCA_CLUSTER_CONFIG_PATH,
99+
RestRequest.Method.GET,
100+
LEGACY_RCA_CLUSTER_CONFIG_PATH),
101+
new ReplacedRoute(
102+
RestRequest.Method.POST,
103+
RCA_CLUSTER_CONFIG_PATH,
104+
RestRequest.Method.POST,
105+
LEGACY_RCA_CLUSTER_CONFIG_PATH),
106+
new ReplacedRoute(
107+
RestRequest.Method.GET,
108+
LOGGING_CLUSTER_CONFIG_PATH,
109+
RestRequest.Method.GET,
110+
LEGACY_LOGGING_CLUSTER_CONFIG_PATH),
111+
new ReplacedRoute(
112+
RestRequest.Method.POST,
113+
LOGGING_CLUSTER_CONFIG_PATH,
114+
RestRequest.Method.POST,
115+
LEGACY_LOGGING_CLUSTER_CONFIG_PATH),
116+
new ReplacedRoute(
117+
RestRequest.Method.GET,
118+
BATCH_METRICS_CLUSTER_CONFIG_PATH,
119+
RestRequest.Method.GET,
120+
LEGACY_BATCH_METRICS_CLUSTER_CONFIG_PATH),
121+
new ReplacedRoute(
122+
RestRequest.Method.POST,
123+
BATCH_METRICS_CLUSTER_CONFIG_PATH,
124+
RestRequest.Method.POST,
125+
LEGACY_BATCH_METRICS_CLUSTER_CONFIG_PATH)));
84126

85127
private final PerformanceAnalyzerClusterSettingHandler clusterSettingHandler;
86128
private final NodeStatsSettingHandler nodeStatsSettingHandler;
@@ -105,7 +147,12 @@ public String getName() {
105147

106148
@Override
107149
public List<Route> routes() {
108-
return ROUTES;
150+
return Collections.emptyList();
151+
}
152+
153+
@Override
154+
public List<ReplacedRoute> replacedRoutes() {
155+
return REPLACED_ROUTES;
109156
}
110157

111158
/**

src/main/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerConfigAction.java

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import static java.util.Collections.unmodifiableList;
3131

3232
import java.io.IOException;
33+
import java.util.Collections;
3334
import java.util.List;
3435
import java.util.Map;
3536
import org.apache.logging.log4j.LogManager;
@@ -63,24 +64,63 @@ public class PerformanceAnalyzerConfigAction extends BaseRestHandler {
6364
"batchMetricsRetentionPeriodMinutes";
6465
public static final String PERFORMANCE_ANALYZER_CONFIG_ACTION =
6566
"PerformanceAnalyzer_Config_Action";
66-
public static final String RCA_CONFIG_PATH = "/_opendistro/_performanceanalyzer/rca/config";
67-
public static final String PA_CONFIG_PATH = "/_opendistro/_performanceanalyzer/config";
68-
public static final String LOGGING_CONFIG_PATH =
69-
"/_opendistro/_performanceanalyzer/logging/config";
70-
public static final String BATCH_METRICS_CONFIG_PATH =
71-
"/_opendistro/_performanceanalyzer/batch/config";
72-
73-
private static final List<Route> ROUTES =
67+
68+
public static final String RCA_CONFIG_PATH = RestConfig.PA_BASE_URI + "/rca/config";
69+
public static final String PA_CONFIG_PATH = RestConfig.PA_BASE_URI + "/config";
70+
public static final String LOGGING_CONFIG_PATH = RestConfig.PA_BASE_URI + "/logging/config";
71+
public static final String BATCH_METRICS_CONFIG_PATH = RestConfig.PA_BASE_URI + "/batch/config";
72+
73+
public static final String LEGACY_RCA_CONFIG_PATH =
74+
RestConfig.LEGACY_PA_BASE_URI + "/rca/config";
75+
public static final String LEGACY_PA_CONFIG_PATH = RestConfig.LEGACY_PA_BASE_URI + "/config";
76+
public static final String LEGACY_LOGGING_CONFIG_PATH =
77+
RestConfig.LEGACY_PA_BASE_URI + "/logging/config";
78+
public static final String LEGACY_BATCH_METRICS_CONFIG_PATH =
79+
RestConfig.LEGACY_PA_BASE_URI + "/batch/config";
80+
81+
private static final List<ReplacedRoute> REPLACED_ROUTES =
7482
unmodifiableList(
7583
asList(
76-
new Route(RestRequest.Method.GET, PA_CONFIG_PATH),
77-
new Route(RestRequest.Method.POST, PA_CONFIG_PATH),
78-
new Route(RestRequest.Method.GET, RCA_CONFIG_PATH),
79-
new Route(RestRequest.Method.POST, RCA_CONFIG_PATH),
80-
new Route(RestRequest.Method.GET, LOGGING_CONFIG_PATH),
81-
new Route(RestRequest.Method.POST, LOGGING_CONFIG_PATH),
82-
new Route(RestRequest.Method.GET, BATCH_METRICS_CONFIG_PATH),
83-
new Route(RestRequest.Method.POST, BATCH_METRICS_CONFIG_PATH)));
84+
new ReplacedRoute(
85+
RestRequest.Method.GET,
86+
PA_CONFIG_PATH,
87+
RestRequest.Method.GET,
88+
LEGACY_PA_CONFIG_PATH),
89+
new ReplacedRoute(
90+
RestRequest.Method.POST,
91+
PA_CONFIG_PATH,
92+
RestRequest.Method.POST,
93+
LEGACY_PA_CONFIG_PATH),
94+
new ReplacedRoute(
95+
RestRequest.Method.GET,
96+
RCA_CONFIG_PATH,
97+
RestRequest.Method.GET,
98+
LEGACY_RCA_CONFIG_PATH),
99+
new ReplacedRoute(
100+
RestRequest.Method.POST,
101+
RCA_CONFIG_PATH,
102+
RestRequest.Method.POST,
103+
LEGACY_RCA_CONFIG_PATH),
104+
new ReplacedRoute(
105+
RestRequest.Method.GET,
106+
LOGGING_CONFIG_PATH,
107+
RestRequest.Method.GET,
108+
LEGACY_LOGGING_CONFIG_PATH),
109+
new ReplacedRoute(
110+
RestRequest.Method.POST,
111+
LOGGING_CONFIG_PATH,
112+
RestRequest.Method.POST,
113+
LEGACY_LOGGING_CONFIG_PATH),
114+
new ReplacedRoute(
115+
RestRequest.Method.GET,
116+
BATCH_METRICS_CONFIG_PATH,
117+
RestRequest.Method.GET,
118+
LEGACY_BATCH_METRICS_CONFIG_PATH),
119+
new ReplacedRoute(
120+
RestRequest.Method.POST,
121+
BATCH_METRICS_CONFIG_PATH,
122+
RestRequest.Method.POST,
123+
LEGACY_BATCH_METRICS_CONFIG_PATH)));
84124

85125
public static PerformanceAnalyzerConfigAction getInstance() {
86126
return instance;
@@ -93,7 +133,12 @@ public static void setInstance(
93133

94134
@Override
95135
public List<Route> routes() {
96-
return ROUTES;
136+
return Collections.emptyList();
137+
}
138+
139+
@Override
140+
public List<ReplacedRoute> replacedRoutes() {
141+
return REPLACED_ROUTES;
97142
}
98143

99144
@Inject
@@ -119,7 +164,8 @@ protected RestChannelConsumer prepareRequest(final RestRequest request, final No
119164
performanceAnalyzerController.isPerformanceAnalyzerEnabled());
120165
if (value instanceof Boolean) {
121166
boolean shouldEnable = (Boolean) value;
122-
if (request.path().contains(RCA_CONFIG_PATH)) {
167+
if (request.path().contains(RCA_CONFIG_PATH)
168+
|| request.path().contains(LEGACY_RCA_CONFIG_PATH)) {
123169
// If RCA needs to be turned on, we need to have PA turned on also.
124170
// If this is not the case, return error.
125171
if (shouldEnable
@@ -129,15 +175,17 @@ protected RestChannelConsumer prepareRequest(final RestRequest request, final No
129175
}
130176

131177
performanceAnalyzerController.updateRcaState(shouldEnable);
132-
} else if (request.path().contains(LOGGING_CONFIG_PATH)) {
178+
} else if (request.path().contains(LOGGING_CONFIG_PATH)
179+
|| request.path().contains(LEGACY_LOGGING_CONFIG_PATH)) {
133180
if (shouldEnable
134181
&& !performanceAnalyzerController.isPerformanceAnalyzerEnabled()) {
135182
return getChannelConsumerWithError(
136183
"Error: PA not enabled. Enable PA before turning Logging on");
137184
}
138185

139186
performanceAnalyzerController.updateLoggingState(shouldEnable);
140-
} else if (request.path().contains(BATCH_METRICS_CONFIG_PATH)) {
187+
} else if (request.path().contains(BATCH_METRICS_CONFIG_PATH)
188+
|| request.path().contains(LEGACY_BATCH_METRICS_CONFIG_PATH)) {
141189
if (shouldEnable
142190
&& !performanceAnalyzerController.isPerformanceAnalyzerEnabled()) {
143191
return getChannelConsumerWithError(

src/main/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerOverridesClusterConfigAction.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,26 @@ public class PerformanceAnalyzerOverridesClusterConfigAction extends BaseRestHan
5555
private static final Logger LOG =
5656
LogManager.getLogger(PerformanceAnalyzerOverridesClusterConfigAction.class);
5757
public static final String PA_CONFIG_OVERRIDES_PATH =
58-
"/_opendistro/_performanceanalyzer/override/cluster/config";
58+
RestConfig.PA_BASE_URI + "/override/cluster/config";
59+
public static final String LEGACY_PA_CONFIG_OVERRIDES_PATH =
60+
RestConfig.LEGACY_PA_BASE_URI + "/override/cluster/config";
5961
private static final String OVERRIDES_FIELD = "overrides";
6062
private static final String REASON_FIELD = "reason";
6163
public static final String OVERRIDE_TRIGGERED_FIELD = "override triggered";
6264

63-
private static final List<Route> ROUTES =
65+
private static final List<ReplacedRoute> REPLACED_ROUTES =
6466
unmodifiableList(
6567
asList(
66-
new Route(RestRequest.Method.GET, PA_CONFIG_OVERRIDES_PATH),
67-
new Route(RestRequest.Method.POST, PA_CONFIG_OVERRIDES_PATH)));
68+
new ReplacedRoute(
69+
RestRequest.Method.GET,
70+
PA_CONFIG_OVERRIDES_PATH,
71+
RestRequest.Method.GET,
72+
LEGACY_PA_CONFIG_OVERRIDES_PATH),
73+
new ReplacedRoute(
74+
RestRequest.Method.POST,
75+
PA_CONFIG_OVERRIDES_PATH,
76+
RestRequest.Method.POST,
77+
LEGACY_PA_CONFIG_OVERRIDES_PATH)));
6878

6979
private final ConfigOverridesClusterSettingHandler configOverridesClusterSettingHandler;
7080
private final ConfigOverridesWrapper overridesWrapper;
@@ -81,7 +91,12 @@ public PerformanceAnalyzerOverridesClusterConfigAction(
8191

8292
@Override
8393
public List<Route> routes() {
84-
return ROUTES;
94+
return Collections.emptyList();
95+
}
96+
97+
@Override
98+
public List<ReplacedRoute> replacedRoutes() {
99+
return REPLACED_ROUTES;
85100
}
86101

87102
/** @return the name of this handler. */

src/main/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerResourceProvider.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,22 @@ public class PerformanceAnalyzerResourceProvider extends BaseRestHandler {
6565
LogManager.getLogger(PerformanceAnalyzerResourceProvider.class);
6666

6767
private static final int HTTP_CLIENT_CONNECTION_TIMEOUT_MILLIS = 200;
68-
private static final String AGENT_PATH = "/_opendistro/_performanceanalyzer/_agent/";
68+
private static final String AGENT_PATH = RestConfig.PA_BASE_URI + "/_agent/";
69+
private static final String LEGACY_AGENT_PATH = RestConfig.LEGACY_PA_BASE_URI + "/_agent/";
6970
private static final String DEFAULT_PORT_NUMBER = "9600";
7071

7172
private String portNumber;
7273
private final boolean isHttpsEnabled;
7374
private static Set<String> SUPPORTED_REDIRECTIONS =
7475
ImmutableSet.of("rca", "metrics", "batch", "actions");
75-
private static final List<Route> ROUTES =
76-
Collections.unmodifiableList(
77-
Collections.singletonList(
78-
new Route(Method.GET, AGENT_PATH + "{redirectEndpoint}")));
76+
77+
private static final List<ReplacedRoute> REPLACED_ROUTES =
78+
Collections.singletonList(
79+
new ReplacedRoute(
80+
Method.GET,
81+
AGENT_PATH + "{redirectEndpoint}",
82+
Method.GET,
83+
LEGACY_AGENT_PATH + "{redirectEndpoint}"));
7984

8085
@Inject
8186
public PerformanceAnalyzerResourceProvider(Settings settings, RestController controller) {
@@ -141,7 +146,12 @@ public String getName() {
141146
/** {@inheritDoc} */
142147
@Override
143148
public List<Route> routes() {
144-
return ROUTES;
149+
return Collections.emptyList();
150+
}
151+
152+
@Override
153+
public List<ReplacedRoute> replacedRoutes() {
154+
return REPLACED_ROUTES;
145155
}
146156

147157
@Override
@@ -234,7 +244,7 @@ public URL getAgentUri(RestRequest request) throws IOException {
234244
String redirectEndpoint = request.param("redirectEndpoint");
235245
String urlScheme = isHttpsEnabled ? "https://" : "http://";
236246
String redirectBasePath =
237-
urlScheme + "localhost:" + portNumber + "/_opendistro/_performanceanalyzer/";
247+
urlScheme + "localhost:" + portNumber + RestConfig.PA_BASE_URI + "/";
238248
// Need to register all params in OpenSearch request else opensearch throws
239249
// illegal_argument_exception
240250
for (String key : request.params().keySet()) {
@@ -243,7 +253,15 @@ public URL getAgentUri(RestRequest request) throws IOException {
243253

244254
// Add Handler whenever add new redirectAgent path
245255
if (SUPPORTED_REDIRECTIONS.contains(redirectEndpoint)) {
246-
String uri = redirectBasePath + request.uri().split(AGENT_PATH)[1];
256+
String uri = null;
257+
if (request.uri().contains(AGENT_PATH)) {
258+
uri = redirectBasePath + request.uri().split(AGENT_PATH)[1];
259+
} else if (request.uri().contains(LEGACY_AGENT_PATH)) {
260+
uri = redirectBasePath + request.uri().split(LEGACY_AGENT_PATH)[1];
261+
} else {
262+
throw new IOException();
263+
}
264+
247265
return new URL(uri);
248266
}
249267
return null;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*
8+
* Modifications Copyright OpenSearch Contributors. See
9+
* GitHub history for details.
10+
*/
11+
12+
/*
13+
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
14+
*
15+
* Licensed under the Apache License, Version 2.0 (the "License").
16+
* You may not use this file except in compliance with the License.
17+
* A copy of the License is located at
18+
*
19+
* http://www.apache.org/licenses/LICENSE-2.0
20+
*
21+
* or in the "license" file accompanying this file. This file is distributed
22+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
23+
* express or implied. See the License for the specific language governing
24+
* permissions and limitations under the License.
25+
*/
26+
27+
package org.opensearch.performanceanalyzer.http_action.config;
28+
29+
/** Shared constants and configuration used by the REST controllers defined by this plugin. */
30+
public class RestConfig {
31+
public static final String PA_BASE_URI = "/_plugins/_performanceanalyzer";
32+
public static final String LEGACY_PA_BASE_URI = "/_opendistro/_performanceanalyzer";
33+
}

0 commit comments

Comments
 (0)