예제 #1
0
  @Test
  public void shouldBeAbleToIndexValuesContainingSpaces() throws Exception {
    final long nodeId = helper.createNode();
    final String key = "key";
    final String value = "value with   spaces  in it";

    String indexName = "spacey-values";
    helper.createNodeIndex(indexName);
    final RestRequest request = RestRequest.req();
    JaxRsResponse response =
        request.post(
            functionalTestHelper.indexNodeUri(indexName), createJsonStringFor(nodeId, key, value));

    assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
    URI location = response.getLocation();
    response.close();
    response =
        request.get(functionalTestHelper.indexNodeUri(indexName, key, URIHelper.encode(value)));
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
    Collection<?> hits = (Collection<?>) JsonHelper.jsonToSingleValue(response.getEntity());
    assertEquals(1, hits.size());
    response.close();

    CLIENT.resource(location).delete();
    response =
        request.get(functionalTestHelper.indexNodeUri(indexName, key, URIHelper.encode(value)));
    hits = (Collection<?>) JsonHelper.jsonToSingleValue(response.getEntity());
    assertEquals(0, hits.size());
  }
  @Override
  public void executeCustomAction(
      CustomActionTriggerContext context, CustomActionLogger actionlogger) throws Exception {
    NewVolumeTaskConfig config = (NewVolumeTaskConfig) context.loadConfigObject();
    super.accountName = config.getAccountName();
    actionlogger.addInfo("Accountname   : " + accountName);

    super.executeCustomAction(context, actionlogger);
    actionlogger.addInfo("finished checking NewVolumeTask accountname");

    String volumePreName = config.getVolumePreName();
    String startNumber = config.getStartNumber();
    String endNumber = config.getEndNumber();
    String volumeSizeUnit = config.getVolumeSizeUnit();
    String volumeSizeNumber = config.getVolumeSizeNumber();
    Boolean destroyVolumeTaskFlag = config.getDestroyVolumeTaskFlag();
    String hostConnection = config.getHostConnection();
    String hostGroupConnection = config.getHostGroupConnection();
    List<String> volumeNameList = new ArrayList<String>();
    List<PureVolume> allVolume = CLIENT.volumes().list();
    List<String> allVolumeName = new ArrayList<String>();
    List<String> noRollBackVolumeName = new ArrayList<String>();

    // actionlogger.addInfo("Parameters are initialized");
    if (startNumber == null) {
      startNumber = "";
    }
    if (endNumber == null) {

      endNumber = "";
    }
    for (PureVolume oneVolume : allVolume) {
      allVolumeName.add(oneVolume.getName());
    }
    // actionlogger.addInfo("Parameters are initialized1 "+startNumber +" e "+endNumber);
    if ((startNumber.equals("") && endNumber.equals(""))
        || (startNumber == null && endNumber == null)) {
      String volumeName = volumePreName;
      volumeNameList.add(volumeName);
      if (allVolumeName != null && allVolumeName.contains(volumeName)) {
        noRollBackVolumeName.add(volumeName);
      }
    } else {
      actionlogger.addInfo("Parameters are initialized5");
      if (startNumber.equals("") || startNumber == null) startNumber = endNumber;
      if (endNumber.equals("") || endNumber == null) endNumber = startNumber;
      // actionlogger.addInfo("Parameters are initialized6");
      for (int i = Integer.parseInt(startNumber); i <= Integer.parseInt(endNumber); i++) {
        String volumeName = volumePreName + Integer.toString(i);
        volumeNameList.add(volumeName);
        if (allVolumeName != null && allVolumeName.contains(volumeName)) {
          // actionlogger.addInfo("Parameters are initialized7");
          noRollBackVolumeName.add(volumeName);
        }
      }
    }
    actionlogger.addInfo("Checked volume name in the volume list ");
    config.setNewVolumeTaskFlag(true);
    config.setNoRollBackVolumeName(StringUtils.join(noRollBackVolumeName, ","));
    actionlogger.addInfo("Set volume task flag ");

    actionlogger.addInfo("Starting creating volume(s)");

    if (destroyVolumeTaskFlag == null) {
      String outVolName = "";
      String outSer = "";
      String connVol = "";
      for (String volumeName : volumeNameList) {
        CLIENT.volumes().create(volumeName, Long.parseLong(volumeSizeNumber), volumeSizeUnit);
        PureVolume volume = CLIENT.volumes().get(volumeName);
        if (volumeNameList.size() == 1) {
          String outVolName1 = volume.getName();
          context.saveOutputValue(PureConstants.TASK_OUTPUT_NAME_VOLUME_NAME, outVolName1);
        }
        if (connVol == "") {
          connVol = accountName + "@" + volumeName;
        } else {
          connVol = connVol + "," + accountName + "@" + volumeName;
        }
        if (outVolName == "") {
          outVolName = volume.getName();
        } else {
          outVolName = outVolName + "," + volume.getName();
        }
        if (outSer == "") {
          outSer = volume.getSerial();
        } else {
          outSer = outSer + "," + volume.getSerial();
        }
      }
      actionlogger.addInfo(
          "Successfully created volume(s) "
              + volumePreName
              + " with range "
              + startNumber
              + "-"
              + endNumber
              + " on Pure FlashArray ["
              + flashArrayAccount.getManagementAddress()
              + "]");

      // PureVolume volume =  CLIENT.volumes().get(volumePreName);
      context.saveOutputValue(PureConstants.TASK_OUTPUT_NAME_VOLUME_IDENTITY, connVol);
      actionlogger.addInfo("Volume Identities as Output is saved");

      context.saveOutputValue(PureConstants.TASK_OUTPUT_NAME_VOLUME_NAMES, outVolName);
      actionlogger.addInfo("Volume Name as Output is saved");

      context.saveOutputValue(PureConstants.TASK_OUTPUT_NAME_VOLUME_SERIAL, outSer);
      actionlogger.addInfo("The Serial Number of this volume is " + outSer);
      actionlogger.addInfo("Serial number as Output is saved");

      context
          .getChangeTracker()
          .undoableResourceModified(
              "AssetType",
              "idstring",
              "Create new volumes",
              "Volumes have been created on " + accountName,
              new DestroyVolumesTask().getTaskName(),
              new DestroyVolumesTaskConfig(config));

    } else {
      actionlogger.addInfo("This is a rollback task for the task of destroying volumes");
      HashMap<String, List<String>> hostMap = splitConnection(hostConnection);
      HashMap<String, List<String>> hostGroupMap = splitConnection(hostGroupConnection);
      for (String volumeName : volumeNameList) {
        try {
          CLIENT.volumes().recover(volumeName);
          if (hostMap != null && hostMap.containsKey(volumeName)) {
            List<String> hostList = hostMap.get(volumeName);
            for (String host : hostList) {
              CLIENT.hosts().connectVolume(host, volumeName);
            }
          }
          if (hostGroupMap != null && hostGroupMap.containsKey(volumeName)) {
            List<String> hostGroupList = hostGroupMap.get(volumeName);
            for (String hostGroup : hostGroupList) {
              CLIENT.hostGroups().connectVolume(hostGroup, volumeName);
            }
          }
        } catch (PureException e) {
          actionlogger.addInfo(
              "Error happens when recovering volume "
                  + volumeName
                  + "Exception: "
                  + e.getMessage());
        }
      }
    }
  }
  @Override
  public void executeCustomAction(
      CustomActionTriggerContext context, CustomActionLogger actionlogger) throws Exception {
    NewHostTaskConfig config = (NewHostTaskConfig) context.loadConfigObject();
    super.accountName = config.getAccountName();

    super.executeCustomAction(context, actionlogger);
    actionlogger.addInfo("finished checking NewHostTask accoutname");

    String hostName = config.getHostName();
    String wwns = config.getWwns();
    String iqns = config.getIqns();
    Boolean deleteHostFlag = config.getDeleteHostFlag();
    String privateVolumes = config.getPrivateVolumes();
    String hostGroupName = config.getHostGroupName();
    List<PureHost> allHost = CLIENT.hosts().list();
    List<String> allHostName = new ArrayList<String>();
    Boolean existHost = false;

    if (wwns == null) {
      wwns = "";
    }
    if (iqns == null) {
      iqns = "";
    }

    for (PureHost oneHost : allHost) {
      if (oneHost.getName().equals(hostName)) {
        existHost = true;
      }
    }
    config.setNewHostFlag(true);
    config.setExistHost(existHost);

    if (deleteHostFlag == null) {
      actionlogger.addInfo(
          "Start creating host "
              + hostName
              + "on Pure FlashArray ["
              + flashArrayAccount.getManagementAddress()
              + "]");
      CLIENT.hosts().create(hostName);

      if (!wwns.equals("")) {
        String[] wwnArray = wwns.split(",");
        CLIENT.hosts().addWwnList(hostName, Arrays.asList(wwnArray));
      }

      if (!iqns.equals("")) {
        String[] iqnArray = iqns.split(",");
        CLIENT.hosts().addIqnList(hostName, Arrays.asList(iqnArray));
      }
      actionlogger.addInfo(
          "Successfully created host "
              + hostName
              + "on Pure FlashArray ["
              + flashArrayAccount.getManagementAddress()
              + "]");
      context.saveOutputValue(PureConstants.TASK_OUTPUT_NAME_HOST_NAME, hostName);
      context.saveOutputValue(PureConstants.TASK_OUTPUT_NAME_HOST_NAMES, hostName);
      actionlogger.addInfo("Host Name as Output is saved");

      context
          .getChangeTracker()
          .undoableResourceModified(
              "AssetType",
              "idstring",
              "NewHost",
              "NewHost has been created on " + config.getAccountName(),
              new DeleteHostTask().getTaskName(),
              new DeleteHostTaskConfig(config));
      String hostIdentity = accountName + "@" + hostName;

      context.saveOutputValue(PureConstants.TASK_OUTPUT_NAME_HOST_IDENTITY, hostIdentity);
      actionlogger.addInfo("Host Identity as Output is saved");
    } else {
      actionlogger.addInfo("This is a rollback task to create the deleted host " + hostName);

      try {
        CLIENT.hosts().create(hostName);
      } catch (PureException e) {
        actionlogger.addInfo(
            "Error happens when rollback task trys to create the deleted host "
                + " Exception: "
                + e.getMessage());
      }

      if (!wwns.equals("")) {
        String[] wwnArray = wwns.split(",");
        try {
          CLIENT.hosts().addWwnList(hostName, Arrays.asList(wwnArray));
        } catch (PureException e) {
          actionlogger.addInfo(
              "Error happens when rollback task trys to add wwns to the deleted host "
                  + " Exception: "
                  + e.getMessage());
        }
      }

      if (!iqns.equals("")) {
        String[] iqnArray = iqns.split(",");
        try {
          CLIENT.hosts().addIqnList(hostName, Arrays.asList(iqnArray));
        } catch (PureException e) {
          actionlogger.addInfo(
              "Error happens when rollback task trys to add iqns to the deleted host "
                  + " Exception: "
                  + e.getMessage());
        }
      }
    }

    if (privateVolumes != null && !privateVolumes.equals("")) {
      String[] volumes = privateVolumes.split(",");
      for (String volume : volumes) {
        try {
          CLIENT.hosts().connectVolume(hostName, volume);
        } catch (PureException e) {
          actionlogger.addInfo(
              "Error happens when connecting with volume "
                  + volume
                  + " Exception: "
                  + e.getMessage());
        }
      }
    }

    // actionlogger.addInfo("hostGroup name is " + hostGroupName);

    if (hostGroupName != null && !hostGroupName.equals("")) {
      List<String> hostList = new ArrayList<String>();
      hostList.add(hostName);
      try {
        CLIENT.hostGroups().addHosts(hostGroupName, hostList);
      } catch (PureException e) {
        actionlogger.addInfo(
            "Error happens when connecting with host group "
                + hostGroupName
                + " Exception: "
                + e.getMessage());
      }
    }
  }