new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/DbUtils.java
public static void startOracleDB(String dbBaseImageName, int dbPort, String dbNamespace, boolean isUseSecret)
      throws ApiException {
    LoggingFacade logger = getLogger();
    Map labels = new HashMap<String, String>();
    labels.put("app", "database");

    Map limits = new HashMap<String, String>();
    limits.put("cpu", "2");
    limits.put("memory", "10Gi");
    limits.put("ephemeral-storage", "8Gi");
    Map requests = new HashMap<String, String>();
    requests.put("cpu", "500m");
    requests.put("ephemeral-storage", "8Gi");

    //create V1Service for Oracle DB
    oracleDBService = new V1Service()
        .apiVersion("v1")
        .kind("Service")
        .metadata(new V1ObjectMeta()
            .name("oracledb")
            .namespace(dbNamespace)
            .labels(labels))
        .spec(new V1ServiceSpec()
            .ports(Arrays.asList(
                new V1ServicePort()
                    .name("tns")
                    .port(1521)
                    .protocol("TCP")
                    .targetPort(new IntOrString(1521))
                    .nodePort(dbPort)))
            .selector(labels)
            .sessionAffinity("None")
            .type("LoadBalancer"));

    logger.info("Create service for Oracle DB service in namespace {0}", dbNamespace);
    boolean serviceCreated = assertDoesNotThrow(() -> Kubernetes.createService(oracleDBService),
        String.format("Create service failed with ApiException for oracleDBService in namespace %s",
            dbNamespace));
    assertTrue(serviceCreated, String.format(
        "Create service failed for OracleDbService in namespace %s ", dbNamespace));

    //create V1Deployment for Oracle DB
    logger.info("Configure V1Deployment in namespace {0} using image {1}", dbNamespace,  dbBaseImageName);
    oracleDbDepl = new V1Deployment()
        .apiVersion("apps/v1")
        .kind("Deployment")
        .metadata(new V1ObjectMeta()
            .name("oracledb")
            .namespace(dbNamespace)
            .labels(labels))
        .spec(new V1DeploymentSpec()
            .replicas(1)
            .selector(new V1LabelSelector()
                .matchLabels(labels))
            .strategy(new V1DeploymentStrategy()
                 .rollingUpdate(new V1RollingUpdateDeployment()
                     .maxSurge(new IntOrString(1))
                     .maxUnavailable(new IntOrString(1)))
                 .type("RollingUpdate"))
            .template(new V1PodTemplateSpec()
                .metadata(new V1ObjectMeta()
                    .labels(labels))
                .spec(new V1PodSpec()
                    .containers(Arrays.asList(
                        new V1Container()
                            .addEnvItem(new V1EnvVar().name("DB_SID").value("devcdb"))
                            .addEnvItem(new V1EnvVar().name("DB_PDB").value("devpdb"))
                            .addEnvItem(new V1EnvVar().name("DB_DOMAIN").value("k8s"))
                            .addEnvItem(new V1EnvVar().name("DB_BUNDLE").value("basic"))
                            .image(dbBaseImageName)
                            .imagePullPolicy("IfNotPresent")
                            .name("oracledb")
                            .ports(Arrays.asList(
                                new V1ContainerPort()
                                .containerPort(1521)
                                .name("tns")
                                .protocol("TCP")
                                .hostPort(1521)))
                            .resources(new V1ResourceRequirements()
                                .limits(limits)
                                .requests(requests))
                            .terminationMessagePath("/dev/termination-log")
                            .terminationMessagePolicy("File")))
                    .dnsPolicy("ClusterFirst")
                    .restartPolicy("Always")
                    .schedulerName("default-scheduler")
                    .terminationGracePeriodSeconds(30L)
                    .imagePullSecrets(isUseSecret ? Arrays.asList(
                        new V1LocalObjectReference()
                            .name(OCR_SECRET_NAME))
                        : null))));

    logger.info("Create deployment for Oracle DB in namespace {0}",
        dbNamespace);
    boolean deploymentCreated = assertDoesNotThrow(() -> Kubernetes.createDeployment(oracleDbDepl),
        String.format("Create deployment failed with ApiException for Oracle DB in namespace %s",
            dbNamespace));
    assertTrue(deploymentCreated, String.format(
        "Create deployment failed for oracleDbDepl in namespace %s ",
        dbNamespace));

    // sleep for a while to make sure the DB pod is created
    try {
      Thread.sleep(2 * 1000);
    } catch (InterruptedException ie) {
        // ignore
    }

    // wait for the Oracle DB pod to be ready
    String dbPodName = assertDoesNotThrow(() -> getPodNameOfDb(dbNamespace),
        String.format("Get Oracle DB pod name failed with ApiException for oracleDBService in namespace %s",
            dbNamespace));
    logger.info("Wait for the oracle Db pod: {0} ready in namespace {1}", dbPodName, dbNamespace);
    withStandardRetryPolicy
        .conditionEvaluationListener(
            condition -> logger.info("Waiting for Oracle DB to be ready in namespace {0} "
                    + "(elapsed time {1}ms, remaining time {2}ms)",
                dbNamespace,
                condition.getElapsedTimeInMS(),
                condition.getRemainingTimeInMS()))
        .until(assertDoesNotThrow(() -> podIsReady(dbNamespace, "app=database", dbPodName),
            "oracleDBService podReady failed with ApiException"));

    // check if DB is ready to be used by searching pod log
    logger.info("Check for DB pod {0} log contains ready message in namespace {1}",
        dbPodName, dbNamespace);
    String msg = "The database is ready for use";
    checkDbReady(msg, dbPodName, dbNamespace);

  }
/**
   * Start Oracle DB pod and service in the specified namespace.
   *
   * @param dbBaseImageName full image name for DB deployment
   * @param dbPort NodePort of DB
   * @param dbNamespace namespace where DB instance is going to start
   */
Start Oracle DB pod and service in the specified namespace.
@param dbBaseImageName full image name for DB deployment
@param dbPort NodePort of DB
@param dbNamespace namespace where DB instance is going to start
Start Oracle DB pod and service in the specified namespace . @param dbBaseImageName full image name for DB deployment @param dbPort NodePort of DB @param dbNamespace namespace where DB instance is going to start
public static void startOracleDB(String dbBaseImageName, int dbPort, String dbNamespace, boolean isUseSecret)
      throws ApiException {
    LoggingFacade logger = getLogger();
    Map labels = new HashMap<String, String>();
    labels.put("app", "database");
    Map limits = new HashMap<String, String>();
    limits.put("cpu", "2");
    limits.put("memory", "10Gi");
    limits.put("ephemeral-storage", "8Gi");
    Map requests = new HashMap<String, String>();
    requests.put("cpu", "500m");
    requests.put("ephemeral-storage", "8Gi");
    oracleDBService = new V1Service()
        .apiVersion("v1")
        .kind("Service")
        .metadata(new V1ObjectMeta()
            .name("oracledb")
            .namespace(dbNamespace)
            .labels(labels))
        .spec(new V1ServiceSpec()
            .ports(Arrays.asList(
                new V1ServicePort()
                    .name("tns")
                    .port(1521)
                    .protocol("TCP")
                    .targetPort(new IntOrString(1521))
                    .nodePort(dbPort)))
            .selector(labels)
            .sessionAffinity("None")
            .type("LoadBalancer"));
    logger.info("Create service for Oracle DB service in namespace {0}", dbNamespace);
    boolean serviceCreated = assertDoesNotThrow(() -> Kubernetes.createService(oracleDBService),
        String.format("Create service failed with ApiException for oracleDBService in namespace %s",
            dbNamespace));
    assertTrue(serviceCreated, String.format(
        "Create service failed for OracleDbService in namespace %s ", dbNamespace));
    logger.info("Configure V1Deployment in namespace {0} using image {1}", dbNamespace,  dbBaseImageName);
    oracleDbDepl = new V1Deployment()
        .apiVersion("apps/v1")
        .kind("Deployment")
        .metadata(new V1ObjectMeta()
            .name("oracledb")
            .namespace(dbNamespace)
            .labels(labels))
        .spec(new V1DeploymentSpec()
            .replicas(1)
            .selector(new V1LabelSelector()
                .matchLabels(labels))
            .strategy(new V1DeploymentStrategy()
                 .rollingUpdate(new V1RollingUpdateDeployment()
                     .maxSurge(new IntOrString(1))
                     .maxUnavailable(new IntOrString(1)))
                 .type("RollingUpdate"))
            .template(new V1PodTemplateSpec()
                .metadata(new V1ObjectMeta()
                    .labels(labels))
                .spec(new V1PodSpec()
                    .containers(Arrays.asList(
                        new V1Container()
                            .addEnvItem(new V1EnvVar().name("DB_SID").value("devcdb"))
                            .addEnvItem(new V1EnvVar().name("DB_PDB").value("devpdb"))
                            .addEnvItem(new V1EnvVar().name("DB_DOMAIN").value("k8s"))
                            .addEnvItem(new V1EnvVar().name("DB_BUNDLE").value("basic"))
                            .image(dbBaseImageName)
                            .imagePullPolicy("IfNotPresent")
                            .name("oracledb")
                            .ports(Arrays.asList(
                                new V1ContainerPort()
                                .containerPort(1521)
                                .name("tns")
                                .protocol("TCP")
                                .hostPort(1521)))
                            .resources(new V1ResourceRequirements()
                                .limits(limits)
                                .requests(requests))
                            .terminationMessagePath("/dev/termination-log")
                            .terminationMessagePolicy("File")))
                    .dnsPolicy("ClusterFirst")
                    .restartPolicy("Always")
                    .schedulerName("default-scheduler")
                    .terminationGracePeriodSeconds(30L)
                    .imagePullSecrets(isUseSecret ? Arrays.asList(
                        new V1LocalObjectReference()
                            .name(OCR_SECRET_NAME))
                        : null))));
    logger.info("Create deployment for Oracle DB in namespace {0}",
        dbNamespace);
    boolean deploymentCreated = assertDoesNotThrow(() -> Kubernetes.createDeployment(oracleDbDepl),
        String.format("Create deployment failed with ApiException for Oracle DB in namespace %s",
            dbNamespace));
    assertTrue(deploymentCreated, String.format(
        "Create deployment failed for oracleDbDepl in namespace %s ",
        dbNamespace));
    try {
      Thread.sleep(2 * 1000);
    } catch (InterruptedException ie) {
    }
    String dbPodName = assertDoesNotThrow(() -> getPodNameOfDb(dbNamespace),
        String.format("Get Oracle DB pod name failed with ApiException for oracleDBService in namespace %s",
            dbNamespace));
    logger.info("Wait for the oracle Db pod: {0} ready in namespace {1}", dbPodName, dbNamespace);
    withStandardRetryPolicy
        .conditionEvaluationListener(
            condition -> logger.info("Waiting for Oracle DB to be ready in namespace {0} "
                    + "(elapsed time {1}ms, remaining time {2}ms)",
                dbNamespace,
                condition.getElapsedTimeInMS(),
                condition.getRemainingTimeInMS()))
        .until(assertDoesNotThrow(() -> podIsReady(dbNamespace, "app=database", dbPodName),
            "oracleDBService podReady failed with ApiException"));
    logger.info("Check for DB pod {0} log contains ready message in namespace {1}",
        dbPodName, dbNamespace);
    String msg = "The database is ready for use";
    checkDbReady(msg, dbPodName, dbNamespace);
  }
public static void startOracleDB ( String dbBaseImageName , int dbPort , String dbNamespace , boolean isUseSecret ) throws ApiException { LoggingFacade logger = getLogger ( ) ; Map labels = new HashMap < String , String > ( ) ; labels . put ( "app" , "database" ) ; Map limits = new HashMap < String , String > ( ) ; limits . put ( "cpu" , "2" ) ; limits . put ( "memory" , "10Gi" ) ; limits . put ( "ephemeral-storage" , "8Gi" ) ; Map requests = new HashMap < String , String > ( ) ; requests . put ( "cpu" , "500m" ) ; requests . put ( "ephemeral-storage" , "8Gi" ) ; oracleDBService = new V1Service ( ) . apiVersion ( "v1" ) . kind ( "Service" ) . metadata ( new V1ObjectMeta ( ) . name ( "oracledb" ) . namespace ( dbNamespace ) . labels ( labels ) ) . spec ( new V1ServiceSpec ( ) . ports ( Arrays . asList ( new V1ServicePort ( ) . name ( "tns" ) . port ( 1521 ) . protocol ( "TCP" ) . targetPort ( new IntOrString ( 1521 ) ) . nodePort ( dbPort ) ) ) . selector ( labels ) . sessionAffinity ( "None" ) . type ( "LoadBalancer" ) ) ; logger . info ( "Create service for Oracle DB service in namespace {0}" , dbNamespace ) ; boolean serviceCreated = assertDoesNotThrow ( ( ) -> Kubernetes . createService ( oracleDBService ) , String . format ( "Create service failed with ApiException for oracleDBService in namespace %s" , dbNamespace ) ) ; assertTrue ( serviceCreated , String . format ( "Create service failed for OracleDbService in namespace %s " , dbNamespace ) ) ; logger . info ( "Configure V1Deployment in namespace {0} using image {1}" , dbNamespace , dbBaseImageName ) ; oracleDbDepl = new V1Deployment ( ) . apiVersion ( "apps/v1" ) . kind ( "Deployment" ) . metadata ( new V1ObjectMeta ( ) . name ( "oracledb" ) . namespace ( dbNamespace ) . labels ( labels ) ) . spec ( new V1DeploymentSpec ( ) . replicas ( 1 ) . selector ( new V1LabelSelector ( ) . matchLabels ( labels ) ) . strategy ( new V1DeploymentStrategy ( ) . rollingUpdate ( new V1RollingUpdateDeployment ( ) . maxSurge ( new IntOrString ( 1 ) ) . maxUnavailable ( new IntOrString ( 1 ) ) ) . type ( "RollingUpdate" ) ) . template ( new V1PodTemplateSpec ( ) . metadata ( new V1ObjectMeta ( ) . labels ( labels ) ) . spec ( new V1PodSpec ( ) . containers ( Arrays . asList ( new V1Container ( ) . addEnvItem ( new V1EnvVar ( ) . name ( "DB_SID" ) . value ( "devcdb" ) ) . addEnvItem ( new V1EnvVar ( ) . name ( "DB_PDB" ) . value ( "devpdb" ) ) . addEnvItem ( new V1EnvVar ( ) . name ( "DB_DOMAIN" ) . value ( "k8s" ) ) . addEnvItem ( new V1EnvVar ( ) . name ( "DB_BUNDLE" ) . value ( "basic" ) ) . image ( dbBaseImageName ) . imagePullPolicy ( "IfNotPresent" ) . name ( "oracledb" ) . ports ( Arrays . asList ( new V1ContainerPort ( ) . containerPort ( 1521 ) . name ( "tns" ) . protocol ( "TCP" ) . hostPort ( 1521 ) ) ) . resources ( new V1ResourceRequirements ( ) . limits ( limits ) . requests ( requests ) ) . terminationMessagePath ( "/dev/termination-log" ) . terminationMessagePolicy ( "File" ) ) ) . dnsPolicy ( "ClusterFirst" ) . restartPolicy ( "Always" ) . schedulerName ( "default-scheduler" ) . terminationGracePeriodSeconds ( 30L ) . imagePullSecrets ( isUseSecret ? Arrays . asList ( new V1LocalObjectReference ( ) . name ( OCR_SECRET_NAME ) ) : null ) ) ) ) ; logger . info ( "Create deployment for Oracle DB in namespace {0}" , dbNamespace ) ; boolean deploymentCreated = assertDoesNotThrow ( ( ) -> Kubernetes . createDeployment ( oracleDbDepl ) , String . format ( "Create deployment failed with ApiException for Oracle DB in namespace %s" , dbNamespace ) ) ; assertTrue ( deploymentCreated , String . format ( "Create deployment failed for oracleDbDepl in namespace %s " , dbNamespace ) ) ; try { Thread . sleep ( 2 * 1000 ) ; } catch ( InterruptedException ie ) { } String dbPodName = assertDoesNotThrow ( ( ) -> getPodNameOfDb ( dbNamespace ) , String . format ( "Get Oracle DB pod name failed with ApiException for oracleDBService in namespace %s" , dbNamespace ) ) ; logger . info ( "Wait for the oracle Db pod: {0} ready in namespace {1}" , dbPodName , dbNamespace ) ; withStandardRetryPolicy . conditionEvaluationListener ( condition -> logger . info ( "Waiting for Oracle DB to be ready in namespace {0} " + "(elapsed time {1}ms, remaining time {2}ms)" , dbNamespace , condition . getElapsedTimeInMS ( ) , condition . getRemainingTimeInMS ( ) ) ) . until ( assertDoesNotThrow ( ( ) -> podIsReady ( dbNamespace , "app=database" , dbPodName ) , "oracleDBService podReady failed with ApiException" ) ) ; logger . info ( "Check for DB pod {0} log contains ready message in namespace {1}" , dbPodName , dbNamespace ) ; String msg = "The database is ready for use" ; checkDbReady ( msg , dbPodName , dbNamespace ) ; }
Start Oracle DB pod and service in the specified namespace.
Start Oracle DB pod and service in the specified namespace .
//create V1Service for Oracle DB //create V1Deployment for Oracle DB // sleep for a while to make sure the DB pod is created // ignore // wait for the Oracle DB pod to be ready // check if DB is ready to be used by searching pod log