Ejemplo n.º 1
0
  protected void executeHttpMethod(final T method) {
    int responseCode = -1;
    VdsManager manager = ResourceManager.getInstance().getVdsManager(getParameters().getVdsId());
    final HttpClient httpclient = manager.getVdsProxy().getHttpClient();
    try {
      FutureTask<Integer> futureTask =
          new FutureTask(
              new Callable<Integer>() {
                @Override
                public Integer call() throws Exception {
                  return httpclient.executeMethod(method);
                }
              });
      Future<Integer> f = ThreadPoolUtil.execute(futureTask);
      if (f.get(Config.<Integer>getValue(getConfigValueTimeLimitForOperation()), TimeUnit.MINUTES)
          == null) {
        responseCode = futureTask.get();
      }
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    } catch (Exception e) {
      log.debug("Exception", e);
      throw createNetworkException(e);
    }

    if (responseCode == getSuccessCode()) {
      Guid createdTask =
          Guid.createGuidFromString(processResponseHeaderValue(getMethod(), "Task-Id", null));
      getVDSReturnValue()
          .setCreationInfo(
              new AsyncTaskCreationInfo(
                  createdTask, getCreatedTaskType(), getParameters().getStoragePoolId()));
      handleOkResponse();
      getVDSReturnValue().setSucceeded(true);
      return;
    }

    processResponseHeaderValue(getMethod(), "Content-type", "application/json");

    String response;
    try {
      response = getMethod().getResponseBodyAsString();
    } catch (Exception e) {
      throw createNetworkException(e);
    }

    Map<String, Object> resultMap = null;
    try {
      resultMap = new ObjectMapper().readValue(response, HashMap.class);
      status = new StatusOnlyReturnForXmlRpc(resultMap);
    } catch (Exception e) {
      throwVdsErrorException("failed to parse response " + response, EngineError.GeneralException);
    }

    proceedProxyReturnValue();
  }
Ejemplo n.º 2
0
  @Override
  protected void executeCommand() {
    updateVdsData();
    if (NeedToUpdateVdsBroker()) {
      initializeVds();
    }

    if (getParameters().isInstallHost()) {
      InstallVdsParameters tempVar =
          new InstallVdsParameters(getVdsId(), getParameters().getPassword());
      tempVar.setIsReinstallOrUpgrade(getParameters().isReinstallOrUpgrade());
      tempVar.setoVirtIsoFile(getParameters().getoVirtIsoFile());
      if (getVdsDao().get(getVdsId()).getStatus() == VDSStatus.InstallingOS) {
        // TODO: remove hack when reinstall api will provider override-firewall parameter.
        // https://bugzilla.redhat.com/show_bug.cgi?id=1177126 - for now we override firewall
        // configurations on each deploy for provisioned host to avoid wrong deployment.
        tempVar.setOverrideFirewall(true);
      } else {
        tempVar.setOverrideFirewall(getParameters().getOverrideFirewall());
      }
      tempVar.setOverrideFirewall(getParameters().getOverrideFirewall());
      tempVar.setActivateHost(getParameters().getActivateHost());
      tempVar.setNetworkProviderId(getParameters().getNetworkProviderId());
      tempVar.setNetworkMappings(getParameters().getNetworkMappings());
      tempVar.setAuthMethod(getParameters().getAuthMethod());
      ArrayList<VdcReturnValueBase> resultList =
          runInternalMultipleActions(
              actionType, new ArrayList<VdcActionParametersBase>(Arrays.asList(tempVar)));

      // Since Host status is set to "Installing", failure of InstallVdsCommand will hang the Host
      // to in that
      // status, therefore needed to fail the command to revert the status.
      if (!resultList.isEmpty()) {
        VdcReturnValueBase vdcReturnValueBase = resultList.get(0);
        if (vdcReturnValueBase != null && !vdcReturnValueBase.getCanDoAction()) {
          ArrayList<String> canDoActionMessages = vdcReturnValueBase.getCanDoActionMessages();
          if (!canDoActionMessages.isEmpty()) {
            // add can do action messages to return value so error messages
            // are returned back to the client
            getReturnValue().getCanDoActionMessages().addAll(canDoActionMessages);
            log.error(
                "Installation/upgrade of Host '{}', '{}' failed: {}",
                getVdsId(),
                getVdsName(),
                StringUtils.join(
                    Backend.getInstance()
                        .getErrorsTranslator()
                        .TranslateErrorText(canDoActionMessages),
                    ","));
          }
          // set can do action to false so can do action messages are
          // returned back to client
          getReturnValue().setCanDoAction(false);
          setSucceeded(false);
          // add old vds dynamic data to compensation context. This
          // way the status will revert back to what it was before
          // starting installation process
          getCompensationContext().snapshotEntityStatus(oldHost.getDynamicData());
          getCompensationContext().stateChanged();
          return;
        }
      }
    }

    if (oldHost.getProtocol() != getParameters().getVdsStaticData().getProtocol()) {
      ResourceManager.getInstance().reestablishConnection(oldHost.getId());
    }

    // set clusters network to be operational (if needed)
    if (oldHost.getStatus() == VDSStatus.Up) {
      List<NetworkCluster> networkClusters =
          DbFacade.getInstance().getNetworkClusterDao().getAllForCluster(oldHost.getVdsGroupId());
      List<Network> networks =
          DbFacade.getInstance().getNetworkDao().getAllForCluster(oldHost.getVdsGroupId());
      for (NetworkCluster item : networkClusters) {
        for (Network net : networks) {
          if (net.getId().equals(item.getNetworkId())) {
            NetworkClusterHelper.setStatus(oldHost.getVdsGroupId(), net);
          }
        }
      }
    }
    alertIfPowerManagementNotConfigured(getParameters().getVdsStaticData());
    testVdsPowerManagementStatus(getParameters().getVdsStaticData());
    checkKdumpIntegrationStatus();
    setSucceeded(true);
  }
 private void setNonOperational(
     VDS host, NonOperationalReason reason, Map<String, String> customLogValues) {
   resourceManager
       .getEventListener()
       .vdsNonOperational(host.getId(), reason, true, Guid.Empty, customLogValues);
 }