new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMonitoringExporter.java
private static void createPvAndPvc(String nameSuffix, String namespace, HashMap<String,String> labels)
          throws IOException {
    logger.info("creating persistent volume and persistent volume claim");
    // create persistent volume and persistent volume claims
    Path pvHostPath = assertDoesNotThrow(
        () -> createDirectories(get(PV_ROOT, "ItMonitoringExporter", "monexp-persistentVolume",nameSuffix)),
            "createDirectories failed with IOException");
    logger.info("Creating PV directory {0}", pvHostPath);
    assertDoesNotThrow(() -> deleteDirectory(pvHostPath.toFile()), "deleteDirectory failed with IOException");
    assertDoesNotThrow(() -> createDirectories(pvHostPath), "createDirectories failed with IOException");

    V1PersistentVolume v1pv = new V1PersistentVolume()
        .spec(new V1PersistentVolumeSpec()
            .addAccessModesItem("ReadWriteMany")
            .storageClassName(nameSuffix)
            .volumeMode("Filesystem")
            .putCapacityItem("storage", Quantity.fromString("10Gi"))
            .persistentVolumeReclaimPolicy("Retain")
            .accessModes(Arrays.asList("ReadWriteMany"))
            .hostPath(new V1HostPathVolumeSource()
                .path(pvHostPath.toString())))
        .metadata(new V1ObjectMeta()
            .name("pv-test" + nameSuffix)
            .namespace(namespace));

    boolean hasLabels = false;
    String labelSelector = null;
    if (labels != null || !labels.isEmpty()) {
      hasLabels = true;
      v1pv.getMetadata().setLabels(labels);
      labelSelector = labels.entrySet()
              .stream()
              .map(e -> e.getKey() + "="
                      + e.getValue())
              .collect(Collectors.joining(","));
    }


    V1PersistentVolumeClaim v1pvc = new V1PersistentVolumeClaim()
        .spec(new V1PersistentVolumeClaimSpec()
        .addAccessModesItem("ReadWriteMany")
        .storageClassName(nameSuffix)
        .volumeName("pv-test" + nameSuffix)
        .resources(new V1ResourceRequirements()
            .putRequestsItem("storage", Quantity.fromString("10Gi"))))
        .metadata(new V1ObjectMeta()
            .name("pvc-" + nameSuffix)
            .namespace(namespace));
    if (hasLabels) {
      v1pvc.getMetadata().setLabels(labels);
    }

    createPVPVCAndVerify(v1pv,v1pvc, labelSelector, namespace);
  }
/**
   * Create a persistent volume and persistent volume claim.
   * @param nameSuffix unique nameSuffix for pv and pvc to create
   * @throws IOException when creating pv path fails
   */
Create a persistent volume and persistent volume claim.
@param nameSuffix unique nameSuffix for pv and pvc to create
@throws IOException when creating pv path fails
Create a persistent volume and persistent volume claim . @param nameSuffix unique nameSuffix for pv and pvc to create @throws IOException when creating pv path fails
private static void createPvAndPvc(String nameSuffix, String namespace, HashMap<String,String> labels)
          throws IOException {
    logger.info("creating persistent volume and persistent volume claim");
    Path pvHostPath = assertDoesNotThrow(
        () -> createDirectories(get(PV_ROOT, "ItMonitoringExporter", "monexp-persistentVolume",nameSuffix)),
            "createDirectories failed with IOException");
    logger.info("Creating PV directory {0}", pvHostPath);
    assertDoesNotThrow(() -> deleteDirectory(pvHostPath.toFile()), "deleteDirectory failed with IOException");
    assertDoesNotThrow(() -> createDirectories(pvHostPath), "createDirectories failed with IOException");
    V1PersistentVolume v1pv = new V1PersistentVolume()
        .spec(new V1PersistentVolumeSpec()
            .addAccessModesItem("ReadWriteMany")
            .storageClassName(nameSuffix)
            .volumeMode("Filesystem")
            .putCapacityItem("storage", Quantity.fromString("10Gi"))
            .persistentVolumeReclaimPolicy("Retain")
            .accessModes(Arrays.asList("ReadWriteMany"))
            .hostPath(new V1HostPathVolumeSource()
                .path(pvHostPath.toString())))
        .metadata(new V1ObjectMeta()
            .name("pv-test" + nameSuffix)
            .namespace(namespace));
    boolean hasLabels = false;
    String labelSelector = null;
    if (labels != null || !labels.isEmpty()) {
      hasLabels = true;
      v1pv.getMetadata().setLabels(labels);
      labelSelector = labels.entrySet()
              .stream()
              .map(e -> e.getKey() + "="
                      + e.getValue())
              .collect(Collectors.joining(","));
    }
    V1PersistentVolumeClaim v1pvc = new V1PersistentVolumeClaim()
        .spec(new V1PersistentVolumeClaimSpec()
        .addAccessModesItem("ReadWriteMany")
        .storageClassName(nameSuffix)
        .volumeName("pv-test" + nameSuffix)
        .resources(new V1ResourceRequirements()
            .putRequestsItem("storage", Quantity.fromString("10Gi"))))
        .metadata(new V1ObjectMeta()
            .name("pvc-" + nameSuffix)
            .namespace(namespace));
    if (hasLabels) {
      v1pvc.getMetadata().setLabels(labels);
    }
    createPVPVCAndVerify(v1pv,v1pvc, labelSelector, namespace);
  }
private static void createPvAndPvc ( String nameSuffix , String namespace , HashMap < String , String > labels ) throws IOException { logger . info ( "creating persistent volume and persistent volume claim" ) ; Path pvHostPath = assertDoesNotThrow ( ( ) -> createDirectories ( get ( PV_ROOT , "ItMonitoringExporter" , "monexp-persistentVolume" , nameSuffix ) ) , "createDirectories failed with IOException" ) ; logger . info ( "Creating PV directory {0}" , pvHostPath ) ; assertDoesNotThrow ( ( ) -> deleteDirectory ( pvHostPath . toFile ( ) ) , "deleteDirectory failed with IOException" ) ; assertDoesNotThrow ( ( ) -> createDirectories ( pvHostPath ) , "createDirectories failed with IOException" ) ; V1PersistentVolume v1pv = new V1PersistentVolume ( ) . spec ( new V1PersistentVolumeSpec ( ) . addAccessModesItem ( "ReadWriteMany" ) . storageClassName ( nameSuffix ) . volumeMode ( "Filesystem" ) . putCapacityItem ( "storage" , Quantity . fromString ( "10Gi" ) ) . persistentVolumeReclaimPolicy ( "Retain" ) . accessModes ( Arrays . asList ( "ReadWriteMany" ) ) . hostPath ( new V1HostPathVolumeSource ( ) . path ( pvHostPath . toString ( ) ) ) ) . metadata ( new V1ObjectMeta ( ) . name ( "pv-test" + nameSuffix ) . namespace ( namespace ) ) ; boolean hasLabels = false ; String labelSelector = null ; if ( labels != null || ! labels . isEmpty ( ) ) { hasLabels = true ; v1pv . getMetadata ( ) . setLabels ( labels ) ; labelSelector = labels . entrySet ( ) . stream ( ) . map ( e -> e . getKey ( ) + "=" + e . getValue ( ) ) . collect ( Collectors . joining ( "," ) ) ; } V1PersistentVolumeClaim v1pvc = new V1PersistentVolumeClaim ( ) . spec ( new V1PersistentVolumeClaimSpec ( ) . addAccessModesItem ( "ReadWriteMany" ) . storageClassName ( nameSuffix ) . volumeName ( "pv-test" + nameSuffix ) . resources ( new V1ResourceRequirements ( ) . putRequestsItem ( "storage" , Quantity . fromString ( "10Gi" ) ) ) ) . metadata ( new V1ObjectMeta ( ) . name ( "pvc-" + nameSuffix ) . namespace ( namespace ) ) ; if ( hasLabels ) { v1pvc . getMetadata ( ) . setLabels ( labels ) ; } createPVPVCAndVerify ( v1pv , v1pvc , labelSelector , namespace ) ; }
Create a persistent volume and persistent volume claim.
Create a persistent volume and persistent volume claim .
// create persistent volume and persistent volume claims