Class AbstractK8SJavaProxy

java.lang.Object
de.iip_ecosphere.platform.ecsRuntime.kubernetes.proxy.AbstractK8SJavaProxy
All Implemented Interfaces:
K8SJavaProxy
Direct Known Subclasses:
AasK8SJavaProxy, HttpK8SJavaProxy

public abstract class AbstractK8SJavaProxy extends Object implements K8SJavaProxy
An abstract for K8SJavaProxy Interface to make shared methods. K8S (Kubernetes)
Author:
Ahmad Alamoush, SSE
  • Field Details

    • proxyType

      private ProxyType proxyType
    • serverAddress

      private String serverAddress
    • okHttpClient

      private okhttp3.OkHttpClient okHttpClient
    • client

      private io.kubernetes.client.openapi.ApiClient client
    • confFile

      private File confFile
  • Constructor Details

    • AbstractK8SJavaProxy

      public AbstractK8SJavaProxy(ProxyType proxyType, String serverAddress)
      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

      public ProxyType getProxyType()
      Returns the proxyType of K8S java proxy.
      Returns:
      the proxyType of K8S java proxy
    • setProxyType

      public void setProxyType(ProxyType proxyType)
      Set the proxyType of K8S java proxy.
      Parameters:
      proxyType - the proxyType of K8S java proxy
    • getServerAddress

      public String getServerAddress()
      Returns the serverAddress which K8S java proxy is connect to.
      Returns:
      the serverAddress which K8S java proxy is connect to
    • setServerAddress

      public void setServerAddress(String serverAddress)
      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:
      getServerSocket in interface K8SJavaProxy
      Parameters:
      localPort - the port on the localhost
      certificatePath - the path of certificate used to create the socket.
      keyPath - the path of key used to create the socket
      algo - the algorithm used for the key
      tlsCheck - check to use tls security
      Returns:
      the created server socket for the specified port on localhost
      Throws:
      IOException
      InvalidKeySpecException
      CertificateException
      KeyStoreException
      NoSuchAlgorithmException
      UnrecoverableKeyException
      KeyManagementException
    • extractK8SRequestByte

      public byte[] extractK8SRequestByte(InputStream reader) throws IOException
      Extract the request as array of bytes from the InputStream of the localhost server socket.
      Specified by:
      extractK8SRequestByte in interface K8SJavaProxy
      Parameters:
      reader - the InputStream for the port on the localhost
      Returns:
      the request as array of bytes
      Throws:
      IOException
    • createK8SRequest

      public K8SRequest createK8SRequest(byte[] requestByte)
      Create K8S request object from the actual array of bytes for the received request.
      Specified by:
      createK8SRequest in interface K8SJavaProxy
      Parameters:
      requestByte - the request as array of bytes
      Returns:
      the new created K8S request object (K8SRequest)
    • sendK8SRequest

      Send the K8S request object to the MasterProxy or K8S apiserver.
      Specified by:
      sendK8SRequest in interface K8SJavaProxy
      Parameters:
      writer - is the output buffer to send watch request stream
      request - the K8S request object (K8SRequest)
      Returns:
      the response from the MasterProxy or K8S apiserver for sent request
      Throws:
      IOException
      CertificateException
      KeyStoreException
      NoSuchAlgorithmException
      KeyManagementException
    • executeK8SJavaClientRequest

      public byte[] executeK8SJavaClientRequest(BufferedOutputStream writer, K8SRequest request) throws IOException
      Execute the request and send it to K8S apiserver.
      Specified by:
      executeK8SJavaClientRequest in interface K8SJavaProxy
      Parameters:
      writer - is the output buffer to send watch request stream
      request - the K8S request object (K8SRequest)
      Returns:
      the response from K8S apiserver for sent DELETE request
      Throws:
      IOException
    • executeWatchK8SJavaClientRequest

      public okhttp3.Response executeWatchK8SJavaClientRequest(K8SRequest request) throws IOException
      Execute the request and send it to K8S apiserver.
      Specified by:
      executeWatchK8SJavaClientRequest in interface K8SJavaProxy
      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:
      formatK8SResponse in interface K8SJavaProxy
      Parameters:
      request - the K8S request object (K8SRequest)
      httpResponse - the response from the MasterProxy
      Returns:
      the formated response
      Throws:
      IOException
      org.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:
      formatWatchK8SResponse in interface K8SJavaProxy
      Parameters:
      writer - is the output buffer to send watch request stream
      request - the K8S request object (K8SRequest)
      httpResponse - the response from the MasterProxy
      Returns:
      the formated response
      Throws:
      IOException
      org.apache.http.ParseException
    • formatK8SResponse

      public byte[] formatK8SResponse(K8SRequest request, okhttp3.Response response) throws IOException
      Format the response from K8S apiserver.
      Specified by:
      formatK8SResponse in interface K8SJavaProxy
      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:
      formatWatchK8SResponse in interface K8SJavaProxy
      Parameters:
      writer - is the output buffer to send watch request stream
      request - 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