new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/CommonTestUtils.java
public static String createImageAndVerify(String imageNameBase,
                                            List<String> wdtModelList,
                                            List<String> appSrcDirList,
                                            List<String> modelPropList,
                                            String baseImageName,
                                            String baseImageTag,
                                            String domainType,
                                            boolean modelType,
                                            String domainHome,
                                            boolean oneArchiveContainsMultiApps) {

    LoggingFacade logger = getLogger();

    // create unique image name with date
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date date = new Date();
    final String imageTag = baseImageTag + "-" + dateFormat.format(date) + "-" + System.currentTimeMillis();
    // Add repository name in image name for Jenkins runs
    final String imageName = REPO_NAME + imageNameBase;
    final String image = imageName + ":" + imageTag;

    List<String> archiveList = new ArrayList<>();
    if (appSrcDirList != null && appSrcDirList.size() != 0 && appSrcDirList.get(0) != null) {
      List<String> archiveAppsList = new ArrayList<>();
      List<String> buildAppDirList = new ArrayList<>(appSrcDirList);
      boolean buildCoherenceGar = false;

      for (String appSrcDir : appSrcDirList) {
        if (appSrcDir.contains(".war") || appSrcDir.contains(".ear")) {
          //remove from build
          buildAppDirList.remove(appSrcDir);
          archiveAppsList.add(appSrcDir);
        }

        if (appSrcDir.contains("coherence")) {
          buildCoherenceGar = true;
        }
      }

      if (archiveAppsList.size() != 0 && archiveAppsList.get(0) != null) {
        assertTrue(archiveApp(defaultAppParams()
                .srcDirList(archiveAppsList)));
        //archive provided ear or war file
        String appName = archiveAppsList.get(0).substring(archiveAppsList.get(0).lastIndexOf("/") + 1,
                appSrcDirList.get(0).lastIndexOf("."));

        // build the archive list
        String zipAppFile = String.format("%s/%s.zip", ARCHIVE_DIR, appName);
        archiveList.add(zipAppFile);

      }

      if (buildAppDirList.size() != 0 && buildAppDirList.get(0) != null) {
        // build an application archive using what is in resources/apps/APP_NAME
        String zipFile = "";
        if (oneArchiveContainsMultiApps) {
          assertTrue(buildAppArchive(defaultAppParams()
                          .srcDirList(buildAppDirList)),
                  String.format("Failed to create app archive for %s", buildAppDirList.get(0)));
          zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, buildAppDirList.get(0));
          // build the archive list
          archiveList.add(zipFile);
        } else if (buildCoherenceGar) {
          // build the Coherence GAR file
          assertTrue(buildCoherenceArchive(defaultAppParams()
                  .srcDirList(buildAppDirList)),
              String.format("Failed to create app archive for %s", buildAppDirList.get(0)));
          zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, buildAppDirList.get(0));
          // build the archive list
          archiveList.add(zipFile);
        } else {
          for (String appName : buildAppDirList) {
            assertTrue(buildAppArchive(defaultAppParams()
                .srcDirList(Collections.singletonList(appName))
                .appName(appName)),
                String.format("Failed to create app archive for %s", appName));
            zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, appName);
            // build the archive list
            archiveList.add(zipFile);
          }
        }
      }
    }

    // Set additional environment variables for WIT
    checkDirectory(WIT_BUILD_DIR);
    Map<String, String> env = new HashMap<>();
    env.put("WLSIMG_BLDDIR", WIT_BUILD_DIR);

    // For k8s 1.16 support and as of May 6, 2020, we presently need a different JDK for these
    // tests and for image tool. This is expected to no longer be necessary once JDK 11.0.8 or
    // the next JDK 14 versions are released.
    String witJavaHome = System.getenv("WIT_JAVA_HOME");
    if (witJavaHome != null) {
      env.put("JAVA_HOME", witJavaHome);
    }

    // build an image using WebLogic Image Tool
    logger.info("Creating image {0} using model directory {1}", image, MODEL_DIR);
    boolean result = false;
    if (!modelType) {  //create a domain home in image image
      result = createImage(
              new WitParams()
                .baseImageName(baseImageName)
                .baseImageTag(baseImageTag)
                .domainType(domainType)
                .modelImageName(imageName)
                .modelImageTag(imageTag)
                .modelFiles(wdtModelList)
                .modelVariableFiles(modelPropList)
                .modelArchiveFiles(archiveList)
                .domainHome(WDT_IMAGE_DOMAINHOME_BASE_DIR + "/" + domainHome)
                .wdtModelOnly(modelType)
                .wdtOperation("CREATE")
                .wdtVersion(WDT_VERSION)
                .env(env)
                .redirect(true));
    } else {
      result = createImage(
              new WitParams()
                .baseImageName(baseImageName)
                .baseImageTag(baseImageTag)
                .domainType(domainType)
                .modelImageName(imageName)
                .modelImageTag(imageTag)
                .modelFiles(wdtModelList)
                .modelVariableFiles(modelPropList)
                .modelArchiveFiles(archiveList)
                .wdtModelOnly(modelType)
                .wdtVersion(WDT_VERSION)
                .env(env)
                .redirect(true));
    }

    assertTrue(result, String.format("Failed to create the image %s using WebLogic Image Tool", image));

    // Check image exists using docker images | grep image tag.
    assertTrue(doesImageExist(imageTag),
            String.format("Image %s does not exist", image));

    logger.info("Image {0} are created successfully", image);
    return image;
  }
/**
   * Create a Docker image for a model in image domain or domain home in image using multiple WDT model
   * files and application ear files.
   * @param imageNameBase - the base mii image name used in local or to construct the image name in repository
   * @param wdtModelList - list of WDT model files used to build the Docker image
   * @param appSrcDirList - list of the sample application source directories used to build sample app ear files
   * @param modelPropList - the WebLogic base image name to be used while creating mii image
   * @param baseImageName - the WebLogic base image name to be used while creating mii image
   * @param baseImageTag - the WebLogic base image tag to be used while creating mii image
   * @param domainType - the type of the WebLogic domain, valid values are "WLS, "JRF", and "Restricted JRF"
   * @param modelType - create a model image only or domain in image. set to true for MII
   * @return image name with tag
   */
Create a Docker image for a model in image domain or domain home in image using multiple WDT model
files and application ear files.
Create a Docker image for a model in image domain or domain home in image using multiple WDT model files and application ear files .
public static String createImageAndVerify(String imageNameBase,
                                            List<String> wdtModelList,
                                            List<String> appSrcDirList,
                                            List<String> modelPropList,
                                            String baseImageName,
                                            String baseImageTag,
                                            String domainType,
                                            boolean modelType,
                                            String domainHome,
                                            boolean oneArchiveContainsMultiApps) {
    LoggingFacade logger = getLogger();
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date date = new Date();
    final String imageTag = baseImageTag + "-" + dateFormat.format(date) + "-" + System.currentTimeMillis();
    final String imageName = REPO_NAME + imageNameBase;
    final String image = imageName + ":" + imageTag;
    List<String> archiveList = new ArrayList<>();
    if (appSrcDirList != null && appSrcDirList.size() != 0 && appSrcDirList.get(0) != null) {
      List<String> archiveAppsList = new ArrayList<>();
      List<String> buildAppDirList = new ArrayList<>(appSrcDirList);
      boolean buildCoherenceGar = false;
      for (String appSrcDir : appSrcDirList) {
        if (appSrcDir.contains(".war") || appSrcDir.contains(".ear")) {
          buildAppDirList.remove(appSrcDir);
          archiveAppsList.add(appSrcDir);
        }
        if (appSrcDir.contains("coherence")) {
          buildCoherenceGar = true;
        }
      }
      if (archiveAppsList.size() != 0 && archiveAppsList.get(0) != null) {
        assertTrue(archiveApp(defaultAppParams()
                .srcDirList(archiveAppsList)));
        String appName = archiveAppsList.get(0).substring(archiveAppsList.get(0).lastIndexOf("/") + 1,
                appSrcDirList.get(0).lastIndexOf("."));
        String zipAppFile = String.format("%s/%s.zip", ARCHIVE_DIR, appName);
        archiveList.add(zipAppFile);
      }
      if (buildAppDirList.size() != 0 && buildAppDirList.get(0) != null) {
        String zipFile = "";
        if (oneArchiveContainsMultiApps) {
          assertTrue(buildAppArchive(defaultAppParams()
                          .srcDirList(buildAppDirList)),
                  String.format("Failed to create app archive for %s", buildAppDirList.get(0)));
          zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, buildAppDirList.get(0));
          archiveList.add(zipFile);
        } else if (buildCoherenceGar) {
          assertTrue(buildCoherenceArchive(defaultAppParams()
                  .srcDirList(buildAppDirList)),
              String.format("Failed to create app archive for %s", buildAppDirList.get(0)));
          zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, buildAppDirList.get(0));
          archiveList.add(zipFile);
        } else {
          for (String appName : buildAppDirList) {
            assertTrue(buildAppArchive(defaultAppParams()
                .srcDirList(Collections.singletonList(appName))
                .appName(appName)),
                String.format("Failed to create app archive for %s", appName));
            zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, appName);
            archiveList.add(zipFile);
          }
        }
      }
    }
    checkDirectory(WIT_BUILD_DIR);
    Map<String, String> env = new HashMap<>();
    env.put("WLSIMG_BLDDIR", WIT_BUILD_DIR);
    String witJavaHome = System.getenv("WIT_JAVA_HOME");
    if (witJavaHome != null) {
      env.put("JAVA_HOME", witJavaHome);
    }
    logger.info("Creating image {0} using model directory {1}", image, MODEL_DIR);
    boolean result = false;
    if (!modelType) {  
      result = createImage(
              new WitParams()
                .baseImageName(baseImageName)
                .baseImageTag(baseImageTag)
                .domainType(domainType)
                .modelImageName(imageName)
                .modelImageTag(imageTag)
                .modelFiles(wdtModelList)
                .modelVariableFiles(modelPropList)
                .modelArchiveFiles(archiveList)
                .domainHome(WDT_IMAGE_DOMAINHOME_BASE_DIR + "/" + domainHome)
                .wdtModelOnly(modelType)
                .wdtOperation("CREATE")
                .wdtVersion(WDT_VERSION)
                .env(env)
                .redirect(true));
    } else {
      result = createImage(
              new WitParams()
                .baseImageName(baseImageName)
                .baseImageTag(baseImageTag)
                .domainType(domainType)
                .modelImageName(imageName)
                .modelImageTag(imageTag)
                .modelFiles(wdtModelList)
                .modelVariableFiles(modelPropList)
                .modelArchiveFiles(archiveList)
                .wdtModelOnly(modelType)
                .wdtVersion(WDT_VERSION)
                .env(env)
                .redirect(true));
    }
    assertTrue(result, String.format("Failed to create the image %s using WebLogic Image Tool", image));
    assertTrue(doesImageExist(imageTag),
            String.format("Image %s does not exist", image));
    logger.info("Image {0} are created successfully", image);
    return image;
  }
public static String createImageAndVerify ( String imageNameBase , List < String > wdtModelList , List < String > appSrcDirList , List < String > modelPropList , String baseImageName , String baseImageTag , String domainType , boolean modelType , String domainHome , boolean oneArchiveContainsMultiApps ) { LoggingFacade logger = getLogger ( ) ; DateFormat dateFormat = new SimpleDateFormat ( "yyyy-MM-dd" ) ; Date date = new Date ( ) ; final String imageTag = baseImageTag + "-" + dateFormat . format ( date ) + "-" + System . currentTimeMillis ( ) ; final String imageName = REPO_NAME + imageNameBase ; final String image = imageName + ":" + imageTag ; List < String > archiveList = new ArrayList < > ( ) ; if ( appSrcDirList != null && appSrcDirList . size ( ) != 0 && appSrcDirList . get ( 0 ) != null ) { List < String > archiveAppsList = new ArrayList < > ( ) ; List < String > buildAppDirList = new ArrayList < > ( appSrcDirList ) ; boolean buildCoherenceGar = false ; for ( String appSrcDir : appSrcDirList ) { if ( appSrcDir . contains ( ".war" ) || appSrcDir . contains ( ".ear" ) ) { buildAppDirList . remove ( appSrcDir ) ; archiveAppsList . add ( appSrcDir ) ; } if ( appSrcDir . contains ( "coherence" ) ) { buildCoherenceGar = true ; } } if ( archiveAppsList . size ( ) != 0 && archiveAppsList . get ( 0 ) != null ) { assertTrue ( archiveApp ( defaultAppParams ( ) . srcDirList ( archiveAppsList ) ) ) ; String appName = archiveAppsList . get ( 0 ) . substring ( archiveAppsList . get ( 0 ) . lastIndexOf ( "/" ) + 1 , appSrcDirList . get ( 0 ) . lastIndexOf ( "." ) ) ; String zipAppFile = String . format ( "%s/%s.zip" , ARCHIVE_DIR , appName ) ; archiveList . add ( zipAppFile ) ; } if ( buildAppDirList . size ( ) != 0 && buildAppDirList . get ( 0 ) != null ) { String zipFile = "" ; if ( oneArchiveContainsMultiApps ) { assertTrue ( buildAppArchive ( defaultAppParams ( ) . srcDirList ( buildAppDirList ) ) , String . format ( "Failed to create app archive for %s" , buildAppDirList . get ( 0 ) ) ) ; zipFile = String . format ( "%s/%s.zip" , ARCHIVE_DIR , buildAppDirList . get ( 0 ) ) ; archiveList . add ( zipFile ) ; } else if ( buildCoherenceGar ) { assertTrue ( buildCoherenceArchive ( defaultAppParams ( ) . srcDirList ( buildAppDirList ) ) , String . format ( "Failed to create app archive for %s" , buildAppDirList . get ( 0 ) ) ) ; zipFile = String . format ( "%s/%s.zip" , ARCHIVE_DIR , buildAppDirList . get ( 0 ) ) ; archiveList . add ( zipFile ) ; } else { for ( String appName : buildAppDirList ) { assertTrue ( buildAppArchive ( defaultAppParams ( ) . srcDirList ( Collections . singletonList ( appName ) ) . appName ( appName ) ) , String . format ( "Failed to create app archive for %s" , appName ) ) ; zipFile = String . format ( "%s/%s.zip" , ARCHIVE_DIR , appName ) ; archiveList . add ( zipFile ) ; } } } } checkDirectory ( WIT_BUILD_DIR ) ; Map < String , String > env = new HashMap < > ( ) ; env . put ( "WLSIMG_BLDDIR" , WIT_BUILD_DIR ) ; String witJavaHome = System . getenv ( "WIT_JAVA_HOME" ) ; if ( witJavaHome != null ) { env . put ( "JAVA_HOME" , witJavaHome ) ; } logger . info ( "Creating image {0} using model directory {1}" , image , MODEL_DIR ) ; boolean result = false ; if ( ! modelType ) { result = createImage ( new WitParams ( ) . baseImageName ( baseImageName ) . baseImageTag ( baseImageTag ) . domainType ( domainType ) . modelImageName ( imageName ) . modelImageTag ( imageTag ) . modelFiles ( wdtModelList ) . modelVariableFiles ( modelPropList ) . modelArchiveFiles ( archiveList ) . domainHome ( WDT_IMAGE_DOMAINHOME_BASE_DIR + "/" + domainHome ) . wdtModelOnly ( modelType ) . wdtOperation ( "CREATE" ) . wdtVersion ( WDT_VERSION ) . env ( env ) . redirect ( true ) ) ; } else { result = createImage ( new WitParams ( ) . baseImageName ( baseImageName ) . baseImageTag ( baseImageTag ) . domainType ( domainType ) . modelImageName ( imageName ) . modelImageTag ( imageTag ) . modelFiles ( wdtModelList ) . modelVariableFiles ( modelPropList ) . modelArchiveFiles ( archiveList ) . wdtModelOnly ( modelType ) . wdtVersion ( WDT_VERSION ) . env ( env ) . redirect ( true ) ) ; } assertTrue ( result , String . format ( "Failed to create the image %s using WebLogic Image Tool" , image ) ) ; assertTrue ( doesImageExist ( imageTag ) , String . format ( "Image %s does not exist" , image ) ) ; logger . info ( "Image {0} are created successfully" , image ) ; return image ; }
Create a Docker image for a model in image domain or domain home in image using multiple WDT model
 files and application ear files.
Create a Docker image for a model in image domain or domain home in image using multiple WDT model files and application ear files .
// create unique image name with date // Add repository name in image name for Jenkins runs //remove from build //archive provided ear or war file // build the archive list // build an application archive using what is in resources/apps/APP_NAME // build the archive list // build the Coherence GAR file // build the archive list // build the archive list // Set additional environment variables for WIT // For k8s 1.16 support and as of May 6, 2020, we presently need a different JDK for these // tests and for image tool. This is expected to no longer be necessary once JDK 11.0.8 or // the next JDK 14 versions are released. // build an image using WebLogic Image Tool //create a domain home in image image // Check image exists using docker images | grep image tag.