forked from apache/incubator-uniffle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[apache#768] feat(cli): Cli method for blacklist update
- Loading branch information
Showing
25 changed files
with
881 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
cli/src/main/java/org/apache/uniffle/api/AdminRestApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.uniffle.api; | ||
|
||
import org.apache.uniffle.client.RestClient; | ||
import org.apache.uniffle.client.UniffleRestClient; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class AdminRestApi { | ||
private UniffleRestClient client; | ||
|
||
private static final String API_BASE_PATH = "admin"; | ||
|
||
private AdminRestApi() {} | ||
|
||
public AdminRestApi(UniffleRestClient client) { | ||
this.client = client; | ||
} | ||
|
||
public String refreshAccessChecker(String checker) { | ||
String path = String.format("/api/server/%s/%s", API_BASE_PATH, "refresh/accessChecker"); | ||
Map<String, Object> params = new HashMap<>(); | ||
params.put("class", checker); | ||
return this.getClient().get(path, params, null); | ||
} | ||
|
||
private RestClient getClient() { | ||
return this.client.getHttpClient(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
cli/src/main/java/org/apache/uniffle/client/HttpClientFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.uniffle.client; | ||
|
||
import org.apache.http.client.config.RequestConfig; | ||
import org.apache.http.conn.ssl.NoopHostnameVerifier; | ||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; | ||
import org.apache.http.conn.ssl.TrustStrategy; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.apache.http.ssl.SSLContexts; | ||
import org.apache.uniffle.client.exception.UniffleRestException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.net.ssl.SSLContext; | ||
|
||
public class HttpClientFactory { | ||
private static final Logger LOG = LoggerFactory.getLogger(HttpClientFactory.class); | ||
|
||
public static CloseableHttpClient createHttpClient(RestClientConf conf) { | ||
RequestConfig requestConfig = | ||
RequestConfig.custom() | ||
.setSocketTimeout(conf.getSocketTimeout()) | ||
.setConnectTimeout(conf.getConnectTimeout()) | ||
.build(); | ||
SSLConnectionSocketFactory sslSocketFactory; | ||
try { | ||
TrustStrategy acceptingTrustStrategy = (cert, authType) -> true; | ||
SSLContext sslContext = | ||
SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build(); | ||
sslSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); | ||
} catch (Exception e) { | ||
LOG.error("Error: ", e); | ||
throw new UniffleRestException("Failed to create HttpClient", e); | ||
} | ||
|
||
return HttpClientBuilder.create() | ||
.setDefaultRequestConfig(requestConfig) | ||
.setSSLSocketFactory(sslSocketFactory) | ||
.build(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
cli/src/main/java/org/apache/uniffle/client/RestClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.uniffle.client; | ||
|
||
import java.util.Map; | ||
|
||
/** A underlying http client interface for common rest request. */ | ||
public interface RestClient extends AutoCloseable { | ||
<T> T get(String path, Map<String, Object> params, Class<T> type, String authHeader); | ||
|
||
String get(String path, Map<String, Object> params, String authHeader); | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
cli/src/main/java/org/apache/uniffle/client/RestClientConf.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.uniffle.client; | ||
|
||
public class RestClientConf { | ||
private int maxAttempts; | ||
private int attemptWaitTime; | ||
private int socketTimeout; | ||
private int connectTimeout; | ||
|
||
public int getMaxAttempts() { | ||
return maxAttempts; | ||
} | ||
|
||
public void setMaxAttempts(int maxAttempts) { | ||
this.maxAttempts = maxAttempts; | ||
} | ||
|
||
public int getAttemptWaitTime() { | ||
return attemptWaitTime; | ||
} | ||
|
||
public void setAttemptWaitTime(int attemptWaitTime) { | ||
this.attemptWaitTime = attemptWaitTime; | ||
} | ||
|
||
public int getSocketTimeout() { | ||
return socketTimeout; | ||
} | ||
|
||
public void setSocketTimeout(int socketTimeout) { | ||
this.socketTimeout = socketTimeout; | ||
} | ||
|
||
public int getConnectTimeout() { | ||
return connectTimeout; | ||
} | ||
|
||
public void setConnectTimeout(int connectTimeout) { | ||
this.connectTimeout = connectTimeout; | ||
} | ||
} |
Oops, something went wrong.