Class AbstractK8SJavaProxy
java.lang.Object
de.iip_ecosphere.platform.ecsRuntime.kubernetes.proxy.AbstractK8SJavaProxy
- All Implemented Interfaces:
K8SJavaProxy
- Direct Known Subclasses:
AasK8SJavaProxy,HttpK8SJavaProxy
An abstract for K8SJavaProxy Interface to make shared methods. K8S
(Kubernetes)
- Author:
- Ahmad Alamoush, SSE
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAbstractK8SJavaProxy(ProxyType proxyType, String serverAddress) Creates a K8S java proxy instance, it will be either MasterProxy or WorkerProxy. -
Method Summary
Modifier and TypeMethodDescriptioncreateK8SRequest(byte[] requestByte) Create K8S request object from the actual array of bytes for the received request.byte[]executeK8SJavaClientRequest(BufferedOutputStream writer, K8SRequest request) Execute the request and send it to K8S apiserver.okhttp3.ResponseExecute the request and send it to K8S apiserver.byte[]extractK8SRequestByte(InputStream reader) Extract the request as array of bytes from the InputStream of the localhost server socket.byte[]formatK8SResponse(K8SRequest request, okhttp3.Response response) Format the response from K8S apiserver.byte[]formatK8SResponse(K8SRequest request, org.apache.http.HttpResponse httpResponse) Format the response from the MasterProxy.byte[]formatWatchK8SResponse(BufferedOutputStream writer, K8SRequest request, okhttp3.Response response) Format the response from K8S apiserver.byte[]formatWatchK8SResponse(BufferedOutputStream writer, K8SRequest request, org.apache.http.HttpResponse httpResponse) Format the response from the MasterProxy.Returns the proxyType of K8S java proxy.Returns the serverAddress which K8S java proxy is connect to.protected static StringgetServerAddress(ProxyType proxyType, String serverIP, String serverPort, boolean tlsCheck) Create the server address and port string which is either the MasterProxy or K8S apiserver.getServerSocket(int localPort, String certificatePath, String keyPath, String algo, boolean tlsCheck) Create server socket for specified port on localhost to receive new requests.byte[]sendK8SRequest(BufferedOutputStream writer, K8SRequest request) Send the K8S request object to the MasterProxy or K8S apiserver.voidsetProxyType(ProxyType proxyType) Set the proxyType of K8S java proxy.voidsetServerAddress(String serverAddress) Set the serverAddress which K8S java proxy is connect to.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface de.iip_ecosphere.platform.ecsRuntime.kubernetes.proxy.K8SJavaProxy
executeK8SDelete, executeK8SGet, executeK8SPatch, executeK8SPost, executeK8SPut
-
Field Details
-
proxyType
-
serverAddress
-
okHttpClient
private okhttp3.OkHttpClient okHttpClient -
client
private io.kubernetes.client.openapi.ApiClient client -
confFile
-
-
Constructor Details
-
AbstractK8SJavaProxy
Creates a K8S java proxy instance, it will be either MasterProxy or WorkerProxy. If it is MasterProxy then serverAddress will be to the K8S apiserver address and port If it is WorkerProxy then serverAddress will be to the MasterProxy address and port- Parameters:
proxyType- the type of the proxy (MasterProxy or WorkerProxy)serverAddress- the address of the MasterProxy or K8S apiserver
-
-
Method Details
-
getProxyType
Returns the proxyType of K8S java proxy.- Returns:
- the proxyType of K8S java proxy
-
setProxyType
Set the proxyType of K8S java proxy.- Parameters:
proxyType- the proxyType of K8S java proxy
-
getServerAddress
Returns the serverAddress which K8S java proxy is connect to.- Returns:
- the serverAddress which K8S java proxy is connect to
-
setServerAddress
Set the serverAddress which K8S java proxy is connect to.- Parameters:
serverAddress- the serverAddress which K8S java proxy is connect to
-
getServerSocket
public ServerSocket getServerSocket(int localPort, String certificatePath, String keyPath, String algo, boolean tlsCheck) throws IOException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, CertificateException, InvalidKeySpecException, KeyManagementException Create server socket for specified port on localhost to receive new requests.- Specified by:
getServerSocketin interfaceK8SJavaProxy- Parameters:
localPort- the port on the localhostcertificatePath- the path of certificate used to create the socket.keyPath- the path of key used to create the socketalgo- the algorithm used for the keytlsCheck- check to use tls security- Returns:
- the created server socket for the specified port on localhost
- Throws:
IOExceptionInvalidKeySpecExceptionCertificateExceptionKeyStoreExceptionNoSuchAlgorithmExceptionUnrecoverableKeyExceptionKeyManagementException
-
extractK8SRequestByte
Extract the request as array of bytes from the InputStream of the localhost server socket.- Specified by:
extractK8SRequestBytein interfaceK8SJavaProxy- Parameters:
reader- the InputStream for the port on the localhost- Returns:
- the request as array of bytes
- Throws:
IOException
-
createK8SRequest
Create K8S request object from the actual array of bytes for the received request.- Specified by:
createK8SRequestin interfaceK8SJavaProxy- Parameters:
requestByte- the request as array of bytes- Returns:
- the new created K8S request object (K8SRequest)
-
sendK8SRequest
public byte[] sendK8SRequest(BufferedOutputStream writer, K8SRequest request) throws IOException, KeyManagementException, NoSuchAlgorithmException, KeyStoreException, CertificateException Send the K8S request object to the MasterProxy or K8S apiserver.- Specified by:
sendK8SRequestin interfaceK8SJavaProxy- Parameters:
writer- is the output buffer to send watch request streamrequest- the K8S request object (K8SRequest)- Returns:
- the response from the MasterProxy or K8S apiserver for sent request
- Throws:
IOExceptionCertificateExceptionKeyStoreExceptionNoSuchAlgorithmExceptionKeyManagementException
-
executeK8SJavaClientRequest
public byte[] executeK8SJavaClientRequest(BufferedOutputStream writer, K8SRequest request) throws IOException Execute the request and send it to K8S apiserver.- Specified by:
executeK8SJavaClientRequestin interfaceK8SJavaProxy- Parameters:
writer- is the output buffer to send watch request streamrequest- the K8S request object (K8SRequest)- Returns:
- the response from K8S apiserver for sent DELETE request
- Throws:
IOException
-
executeWatchK8SJavaClientRequest
Execute the request and send it to K8S apiserver.- Specified by:
executeWatchK8SJavaClientRequestin interfaceK8SJavaProxy- Parameters:
request- the K8S request object (K8SRequest)- Returns:
- the response from K8S apiserver for sent DELETE request
- Throws:
IOException
-
formatK8SResponse
public byte[] formatK8SResponse(K8SRequest request, org.apache.http.HttpResponse httpResponse) throws org.apache.http.ParseException, IOException Format the response from the MasterProxy.- Specified by:
formatK8SResponsein interfaceK8SJavaProxy- Parameters:
request- the K8S request object (K8SRequest)httpResponse- the response from the MasterProxy- Returns:
- the formated response
- Throws:
IOExceptionorg.apache.http.ParseException
-
formatWatchK8SResponse
public byte[] formatWatchK8SResponse(BufferedOutputStream writer, K8SRequest request, org.apache.http.HttpResponse httpResponse) throws org.apache.http.ParseException, IOException Format the response from the MasterProxy.- Specified by:
formatWatchK8SResponsein interfaceK8SJavaProxy- Parameters:
writer- is the output buffer to send watch request streamrequest- the K8S request object (K8SRequest)httpResponse- the response from the MasterProxy- Returns:
- the formated response
- Throws:
IOExceptionorg.apache.http.ParseException
-
formatK8SResponse
Format the response from K8S apiserver.- Specified by:
formatK8SResponsein interfaceK8SJavaProxy- Parameters:
request- the K8S request object (K8SRequest)response- the response from the K8S apiserver- Returns:
- the formated response
- Throws:
IOException
-
formatWatchK8SResponse
public byte[] formatWatchK8SResponse(BufferedOutputStream writer, K8SRequest request, okhttp3.Response response) throws IOException Format the response from K8S apiserver.- Specified by:
formatWatchK8SResponsein interfaceK8SJavaProxy- Parameters:
writer- is the output buffer to send watch request streamrequest- the K8S request object (K8SRequest)response- the response from the K8S apiserver- Returns:
- the formated response
- Throws:
IOException
-
getServerAddress
protected static String getServerAddress(ProxyType proxyType, String serverIP, String serverPort, boolean tlsCheck) Create the server address and port string which is either the MasterProxy or K8S apiserver. If it is MasterProxy then serverAddress will be to the K8S apiserver address and port If it is WorkerProxy then serverAddress will be to the MasterProxy address and port- Parameters:
proxyType- the type of the proxy (MasterProxy or WorkerProxy)serverIP- the IP Address of the server (either the MasterProxy or K8S apiserver)serverPort- the port of the server (either the MasterProxy or K8S apiserver)tlsCheck- check to use tls security- Returns:
- the server address and port as String
-