Пример #1
0
 public static ModelNode checkOperationResult(
     ModelNode operation, ModelNode result, Outcome expectedOutcome) {
   String outcome = result.get(OUTCOME).asString();
   switch (expectedOutcome) {
     case SUCCESS:
       if (!SUCCESS.equals(outcome)) {
         System.out.println("Failed: " + operation);
         System.out.print("Result: " + result);
         fail(result.get(FAILURE_DESCRIPTION).asString());
       }
       break;
     case UNAUTHORIZED:
       {
         if (!FAILED.equals(outcome)) {
           fail("Didn't fail: " + result.asString());
         }
         if (!result.get(FAILURE_DESCRIPTION).asString().contains("13456")
             && !result.asString().contains("11360")
             && !result.asString().contains("11361")
             && !result.asString().contains("11362")
             && !result.asString().contains("11363")) {
           fail("Incorrect failure type: " + result.asString());
         }
         break;
       }
     case HIDDEN:
       {
         if (!FAILED.equals(outcome)) {
           fail("Didn't fail: " + result.asString());
         }
         String failureDesc = result.get(FAILURE_DESCRIPTION).asString();
         if (!failureDesc.contains("14807")
             && !failureDesc.contains("14883")
             && !failureDesc.contains("11340")) {
           fail("Incorrect failure type: " + result.asString());
         }
         break;
       }
     case FAILED:
       {
         if (!FAILED.equals(outcome)) {
           fail("Didn't fail: " + result.asString());
         }
         String failureDesc = result.get(FAILURE_DESCRIPTION).asString();
         if (failureDesc.contains("14807")
             || failureDesc.contains("14883")
             || failureDesc.contains("13456")
             || failureDesc.contains("11340")) {
           fail("Incorrect failure type: " + result.asString());
         }
         break;
       }
     default:
       throw new IllegalStateException();
   }
   return result;
 }
  @Test
  public void testApplicationException() throws Exception {

    taskletStep.execute(stepExecution);
    assertEquals(FAILED, stepExecution.getStatus());
    assertEquals(FAILED.toString(), stepExecution.getExitStatus().getExitCode());
  }
Пример #3
0
 public static void addRoleMapping(String role, ModelControllerClient client) throws IOException {
   String address = ROLE_MAPPING_ADDRESS_BASE + role;
   ModelNode readOp = createOpNode(address, READ_RESOURCE_OPERATION);
   if (FAILED.equals(client.execute(readOp).get(OUTCOME).asString())) {
     ModelNode addOp = createOpNode(address, ADD);
     executeOperation(client, addOp, Outcome.SUCCESS);
   }
 }
Пример #4
0
  /** {@inheritDoc} */
  @Override
  public void resetCreationTime() {
    if (FAILED.equals(status) || STOPPED.equals(status) || IN_QUEUE.equals(status)) {
      creationTime = System.currentTimeMillis();
      return;
    }

    creationTime = descriptor == null ? System.currentTimeMillis() : descriptor.getCreationTime();
  }
  @Override
  public TargetModuleID[] getAvailableModules(ModuleType filterType) throws TargetException {
    try {
      List<TargetModuleID> list = new ArrayList<TargetModuleID>();

      final ModelNode operation = new ModelNode();
      operation.get(OP).set(READ_CHILDREN_NAMES_OPERATION);
      operation.get(CHILD_TYPE).set(DEPLOYMENT);
      ModelNode result = modelControllerClient.execute(operation);
      if (FAILED.equals(result.get(OUTCOME).asString()))
        throw new IllegalStateException(MESSAGES.managementRequestFailed(result));

      List<ModelNode> nodeList = result.get(RESULT).asList();
      for (ModelNode node : nodeList) {
        String moduleID = node.asString();
        ModuleType moduleType = null;
        if (moduleID.endsWith(".ear")) {
          moduleType = ModuleType.EAR;
        } else if (moduleID.endsWith(".war")) {
          moduleType = ModuleType.WAR;
        } else if (moduleID.endsWith(".rar")) {
          moduleType = ModuleType.RAR;
        } else if (moduleID.endsWith(".jar")) {
          // [TODO] not every jar is also an ejb jar
          moduleType = ModuleType.EJB;
        }
        if (moduleType == null) {
          ROOT_LOGGER.cannotDetermineModuleType(node);
          continue;
        }
        if (filterType == null || filterType.equals(moduleType)) {
          TargetModuleIDImpl targetModuleID =
              new TargetModuleIDImpl(this, moduleID, null, moduleType);
          Boolean state = runtimeState.get(targetModuleID);
          targetModuleID.setRunning(state != null ? state : Boolean.TRUE);
          list.add(targetModuleID);
        }
      }
      TargetModuleID[] targetModuleIDs = new TargetModuleID[list.size()];
      list.toArray(targetModuleIDs);
      return targetModuleIDs;
    } catch (Exception e) {
      TargetException tex = new TargetException("Failed to get available modules");
      tex.initCause(e);
      throw tex;
    }
  }
Пример #6
0
  /**
   * Handles a operation request via HTTP.
   *
   * @param http The HttpExchange object that allows access to the request and response.
   * @throws IOException if an error occurs while attempting to process the request.
   */
  private void processRequest(final HttpExchange http) throws IOException {
    final URI request = http.getRequestURI();
    final String requestMethod = http.getRequestMethod();

    boolean isGet = GET.equals(requestMethod);
    if (!isGet && !POST.equals(requestMethod)) {
      http.sendResponseHeaders(METHOD_NOT_ALLOWED, -1);

      return;
    }

    ModelNode dmr;
    ModelNode response;
    int status = OK;

    Headers requestHeaders = http.getRequestHeaders();
    boolean encode =
        APPLICATION_DMR_ENCODED.equals(requestHeaders.getFirst(ACCEPT))
            || APPLICATION_DMR_ENCODED.equals(requestHeaders.getFirst(CONTENT_TYPE));

    try {
      dmr = isGet ? convertGetRequest(request) : convertPostRequest(http.getRequestBody(), encode);
    } catch (IllegalArgumentException iae) {
      ROOT_LOGGER.debugf("Unable to construct ModelNode '%s'", iae.getMessage());
      http.sendResponseHeaders(INTERNAL_SERVER_ERROR, -1);

      return;
    }

    try {
      response = modelController.execute(new OperationBuilder(dmr).build());
    } catch (Throwable t) {
      ROOT_LOGGER.modelRequestError(t);
      http.sendResponseHeaders(INTERNAL_SERVER_ERROR, -1);

      return;
    }

    if (response.hasDefined(OUTCOME) && FAILED.equals(response.get(OUTCOME).asString())) {
      status = INTERNAL_SERVER_ERROR;
    }

    boolean pretty = dmr.hasDefined("json.pretty") && dmr.get("json.pretty").asBoolean();
    writeResponse(http, isGet, pretty, response, status, encode);
  }
 public boolean isFailed() {
   return currentState == FAILED.getStateCode();
 }