コード例 #1
0
 private void checkSuccessful(final ModelNode result, final ModelNode operation)
     throws UnSuccessfulOperationException {
   if (!SUCCESS.equals(result.get(OUTCOME).asString())) {
     logger.error("Operation " + operation + " did not succeed. Result was " + result);
     throw new UnSuccessfulOperationException(result.get(FAILURE_DESCRIPTION).toString());
   }
 }
コード例 #2
0
 private boolean checkHostServersStarted(DomainClient masterClient, String host) {
   try {
     ModelNode op =
         Util.createEmptyOperation(
             READ_CHILDREN_NAMES_OPERATION, PathAddress.pathAddress(HOST, host));
     op.get(CHILD_TYPE).set(SERVER);
     ModelNode ret = DomainTestUtils.executeForResult(op, masterClient);
     List<ModelNode> list = ret.asList();
     for (ModelNode entry : list) {
       String server = entry.asString();
       op =
           Util.createEmptyOperation(
               READ_ATTRIBUTE_OPERATION,
               PathAddress.pathAddress(HOST, host).append(SERVER, server));
       op.get(NAME).set("server-state");
       ModelNode state = DomainTestUtils.executeForResult(op, masterClient);
       if (SUCCESS.equals(state.get(OUTCOME).asString())) {
         return "running".equals(state.get(RESULT).asString());
       }
     }
     return false;
   } catch (Exception e) {
     return false;
   }
 }
コード例 #3
0
 private void execute(ModelControllerClient client, ModelNode op) throws IOException {
   op.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
   ModelNode response = client.execute(op);
   if (!SUCCESS.equals(response.get(OUTCOME).asString())) {
     Assert.fail("Could not execute op: '" + op + "', result: " + response);
   }
 }
  /**
   * Acquire the lock so that the scene can be acted upon.
   *
   * <p>This returns null if the lock was just acquired, otherwise it returns {@link
   * Result.Status#SUCCESS} if the lock already belonged to that thread, or another instance (see
   * {@link Result#getStatus()}) if an error occurred.
   *
   * @param timeout the time to wait if another rendering is happening.
   * @return null if the lock was just acquire or another result depending on the state.
   * @throws IllegalStateException if the current context is different than the one owned by the
   *     scene.
   */
  private Result acquireLock(long timeout) {
    ReentrantLock lock = Bridge.getLock();
    if (!lock.isHeldByCurrentThread()) {
      try {
        boolean acquired = lock.tryLock(timeout, TimeUnit.MILLISECONDS);

        if (!acquired) {
          return ERROR_TIMEOUT.createResult();
        }
      } catch (InterruptedException e) {
        return ERROR_LOCK_INTERRUPTED.createResult();
      }
    } else {
      // This thread holds the lock already. Checks that this wasn't for a different context.
      // If this is called by init, mContext will be null and so should sCurrentContext
      // anyway
      if (mContext != sCurrentContext) {
        throw new IllegalStateException(
            "Acquiring different scenes from same thread without releases");
      }
      return SUCCESS.createResult();
    }

    return null;
  }
コード例 #5
0
 private void removeResource(String address) throws IOException {
   ModelNode op = createOpNode(address, READ_RESOURCE_OPERATION);
   ModelNode result = getManagementClient().getControllerClient().execute(op);
   if (SUCCESS.equals(result.get(OUTCOME).asString())) {
     op = createOpNode(address, REMOVE);
     result = getManagementClient().getControllerClient().execute(op);
     assertEquals(result.asString(), SUCCESS, result.get(OUTCOME).asString());
   }
 }
コード例 #6
0
 protected static ModelNode execute(ModelControllerClient client, ModelNode operation)
     throws Exception {
   ModelNode response = client.execute(operation);
   boolean success = SUCCESS.equals(response.get(OUTCOME).asString());
   if (success) {
     return response.get(RESULT);
   }
   throw new Exception("Operation failed");
 }
コード例 #7
0
  @Override
  public boolean delete(final ObjectId id) {
    final byte[] rawKey = id.getRawValue();
    final DatabaseEntry key = new DatabaseEntry(rawKey);

    final OperationStatus status = objectDb.delete(txn.getTransaction(), key);

    return SUCCESS.equals(status);
  }
コード例 #8
0
 private boolean makeOneLog() throws IOException {
   ModelNode op =
       Util.getWriteAttributeOperation(
           auditLogConfigAddress,
           AuditLogLoggerResourceDefinition.LOG_BOOT.getName(),
           new ModelNode(true));
   ModelNode result = managementClient.getControllerClient().execute(op);
   return SUCCESS.equals(result.get(OUTCOME).asString());
 }
コード例 #9
0
ファイル: RbacUtil.java プロジェクト: jerrinot/jboss-as
 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;
 }
コード例 #10
0
  @Override
  protected List<ObjectId> lookUpInternal(final byte[] partialId) {

    DatabaseEntry key;
    {
      byte[] keyData = partialId.clone();
      key = new DatabaseEntry(keyData);
    }

    DatabaseEntry data = new DatabaseEntry();
    data.setPartial(0, 0, true); // do not retrieve data

    List<ObjectId> matches;

    CursorConfig cursorConfig = new CursorConfig();
    cursorConfig.setReadCommitted(true);
    cursorConfig.setReadUncommitted(false);

    Cursor cursor = objectDb.openCursor(txn.getTransaction(), cursorConfig);
    try {
      // position cursor at the first closest key to the one looked up
      OperationStatus status = cursor.getSearchKeyRange(key, data, LockMode.DEFAULT);
      if (SUCCESS.equals(status)) {
        matches = new ArrayList<ObjectId>(2);
        final byte[] compKey = new byte[partialId.length];
        while (SUCCESS.equals(status)) {
          byte[] keyData = key.getData();
          System.arraycopy(keyData, 0, compKey, 0, compKey.length);
          if (Arrays.equals(partialId, compKey)) {
            matches.add(new ObjectId(keyData));
          } else {
            break;
          }
          status = cursor.getNext(key, data, LockMode.DEFAULT);
        }
      } else {
        matches = Collections.emptyList();
      }
      return matches;
    } finally {
      cursor.close();
    }
  }
コード例 #11
0
 protected void removeResource(String address) throws IOException {
   ModelNode op = createOpNode(address, READ_RESOURCE_OPERATION);
   DomainClient domainClient = testSupport.getDomainMasterLifecycleUtil().getDomainClient();
   ModelNode result = domainClient.execute(op);
   if (SUCCESS.equals(result.get(OUTCOME).asString())) {
     op = createOpNode(address, REMOVE);
     result = domainClient.execute(op);
     assertEquals(result.asString(), SUCCESS, result.get(OUTCOME).asString());
   }
 }
  /**
   * Prepares the scene for action.
   *
   * <p>This call is blocking if another rendering/inflating is currently happening, and will return
   * whether the preparation worked.
   *
   * <p>The preparation can fail if another rendering took too long and the timeout was elapsed.
   *
   * <p>More than one call to this from the same thread will have no effect and will return {@link
   * Result.Status#SUCCESS}.
   *
   * <p>After scene actions have taken place, only one call to {@link #release()} must be done.
   *
   * @param timeout the time to wait if another rendering is happening.
   * @return whether the scene was prepared
   * @see #release()
   * @throws IllegalStateException if {@link #init(long)} was never called.
   */
  public Result acquire(long timeout) {
    if (mContext == null) {
      throw new IllegalStateException("After scene creation, #init() must be called");
    }

    // acquire the lock. if the result is null, lock was just acquired, otherwise, return
    // the result.
    Result result = acquireLock(timeout);
    if (result != null) {
      return result;
    }

    setUp();

    return SUCCESS.createResult();
  }
コード例 #13
0
ファイル: ServerManager.java プロジェクト: oscerd/infinispan
  private String getHotRodCacheContainer(ModelControllerClient client) throws IOException {
    PathAddress pathAddress =
        PathAddress.pathAddress(SUBSYSTEM, INFINISPAN_ENDPOINT_SUBSYSTEM_NAME)
            .append("hotrod-connector", "hotrod-connector");

    ModelNode op = new ModelNode();
    op.get(OP).set(READ_ATTRIBUTE_OPERATION);
    op.get(OP_ADDR).set(pathAddress.toModelNode());
    op.get("name").set("cache-container");

    ModelNode resp = client.execute(op);
    if (!SUCCESS.equals(resp.get(OUTCOME).asString())) {
      throw new IllegalArgumentException(resp.asString());
    }
    return resp.get(RESULT).asString();
  }
コード例 #14
0
  /**
   * Redirects to different view by checking the view type.
   *
   * @return the result code.
   * @throws Exception if there is error.
   */
  @Override
  public String execute() throws Exception {
    String resultCode = super.execute();
    if (SUCCESS.equals(resultCode)) {
      if (formData.getViewType().equals(ProjectMilestoneViewForm.LIST_VIEW)) {
        return ProjectMilestoneViewForm.LIST_VIEW;
      }
      if (formData.getViewType().equals(ProjectMilestoneViewForm.CALENDAR_VIEW)) {
        return ProjectMilestoneViewForm.CALENDAR_VIEW;
      }
      if (formData.getViewType().equals(ProjectMilestoneViewForm.MULTIPLE_CREATION_VIEW)) {
        return ProjectMilestoneViewForm.MULTIPLE_CREATION_VIEW;
      }
    }

    return resultCode;
  }
  @Override
  public void upgradeInternal(
      ServerHttpRequest request,
      ServerHttpResponse response,
      String selectedProtocol,
      List<Extension> extensions,
      Endpoint endpoint)
      throws HandshakeFailureException {

    HttpServletRequest servletRequest = getHttpServletRequest(request);
    HttpServletResponse servletResponse = getHttpServletResponse(response);

    TyrusServerContainer serverContainer = (TyrusServerContainer) getContainer(servletRequest);
    TyrusWebSocketEngine engine = (TyrusWebSocketEngine) serverContainer.getWebSocketEngine();
    Object tyrusEndpoint = null;
    boolean success;

    try {
      // Shouldn't matter for processing but must be unique
      String path = "/" + random.nextLong();
      tyrusEndpoint =
          createTyrusEndpoint(
              endpoint, path, selectedProtocol, extensions, serverContainer, engine);
      getEndpointHelper().register(engine, tyrusEndpoint);

      HttpHeaders headers = request.getHeaders();
      RequestContext requestContext = createRequestContext(servletRequest, path, headers);
      TyrusUpgradeResponse upgradeResponse = new TyrusUpgradeResponse();
      UpgradeInfo upgradeInfo = engine.upgrade(requestContext, upgradeResponse);
      success = SUCCESS.equals(upgradeInfo.getStatus());
      if (success) {
        if (logger.isTraceEnabled()) {
          logger.trace("Successful request upgrade: " + upgradeResponse.getHeaders());
        }
        handleSuccess(servletRequest, servletResponse, upgradeInfo, upgradeResponse);
      }
    } catch (Exception ex) {
      unregisterTyrusEndpoint(engine, tyrusEndpoint);
      throw new HandshakeFailureException("Error during handshake: " + request.getURI(), ex);
    }

    unregisterTyrusEndpoint(engine, tyrusEndpoint);
    if (!success) {
      throw new HandshakeFailureException("Unexpected handshake failure: " + request.getURI());
    }
  }
  /**
   * Initializes and acquires the scene, creating various Android objects such as context, inflater,
   * and parser.
   *
   * @param timeout the time to wait if another rendering is happening.
   * @return whether the scene was prepared
   * @see #acquire(long)
   * @see #release()
   */
  public Result init(long timeout) {
    // acquire the lock. if the result is null, lock was just acquired, otherwise, return
    // the result.
    Result result = acquireLock(timeout);
    if (result != null) {
      return result;
    }

    // setup the ParserFactory
    ParserFactory.setParserFactory(mParams.getLayoutlibCallback().getParserFactory());

    HardwareConfig hardwareConfig = mParams.getHardwareConfig();

    // setup the display Metrics.
    DisplayMetrics metrics = new DisplayMetrics();
    metrics.densityDpi = metrics.noncompatDensityDpi = hardwareConfig.getDensity().getDpiValue();

    metrics.density =
        metrics.noncompatDensity = metrics.densityDpi / (float) DisplayMetrics.DENSITY_DEFAULT;

    metrics.scaledDensity = metrics.noncompatScaledDensity = metrics.density;

    metrics.widthPixels = metrics.noncompatWidthPixels = hardwareConfig.getScreenWidth();
    metrics.heightPixels = metrics.noncompatHeightPixels = hardwareConfig.getScreenHeight();
    metrics.xdpi = metrics.noncompatXdpi = hardwareConfig.getXdpi();
    metrics.ydpi = metrics.noncompatYdpi = hardwareConfig.getYdpi();

    RenderResources resources = mParams.getResources();

    // build the context
    mContext =
        new BridgeContext(
            mParams.getProjectKey(),
            metrics,
            resources,
            mParams.getAssets(),
            mParams.getLayoutlibCallback(),
            getConfiguration(),
            mParams.getTargetSdkVersion(),
            mParams.isRtlSupported());

    setUp();

    return SUCCESS.createResult();
  }
コード例 #17
0
  @Override
  public ModelNode getProfileOperations(String profileName) {
    ModelNode operation = new ModelNode();

    operation.get(OP).set(DESCRIBE);
    operation
        .get(OP_ADDR)
        .set(PathAddress.pathAddress(PathElement.pathElement(PROFILE, profileName)).toModelNode());

    ModelNode rsp = getValue().execute(operation, null, null, null);
    if (!rsp.hasDefined(OUTCOME) || !SUCCESS.equals(rsp.get(OUTCOME).asString())) {
      ModelNode msgNode = rsp.get(FAILURE_DESCRIPTION);
      String msg =
          msgNode.isDefined() ? msgNode.toString() : MESSAGES.failedProfileOperationsRetrieval();
      throw new RuntimeException(msg);
    }
    return rsp.require(RESULT);
  }
コード例 #18
0
  /**
   * Checks whether or not the server is running.
   *
   * <p>Note that if this client has been {@linkplain #close() closed} the state of the server
   * cannot be checked.
   *
   * @return {@code true} if the server is running, otherwise {@code false}
   * @throws IllegalStateException if this has been {@linkplain #close() closed}
   */
  public boolean isServerInRunningState() {
    checkState();
    try {
      ModelNode op = new ModelNode();
      op.get(OP).set(READ_ATTRIBUTE_OPERATION);
      op.get(OP_ADDR).setEmptyList();
      op.get(NAME).set("server-state");

      ModelNode rsp = client.execute(op);
      return SUCCESS.equals(rsp.get(OUTCOME).asString())
          && !CONTROLLER_PROCESS_STATE_STARTING.equals(rsp.get(RESULT).asString())
          && !CONTROLLER_PROCESS_STATE_STOPPING.equals(rsp.get(RESULT).asString());
    } catch (RuntimeException rte) {
      throw rte;
    } catch (IOException ex) {
      return false;
    }
  }
コード例 #19
0
  /** @see org.geogit.storage.ObjectDatabase#put(org.geogit.storage.ObjectWriter) */
  @Override
  protected boolean putInternal(final ObjectId id, final byte[] rawData, final boolean override)
      throws IOException {
    final byte[] rawKey = id.getRawValue();
    DatabaseEntry key = new DatabaseEntry(rawKey);
    DatabaseEntry data = new DatabaseEntry(rawData);

    OperationStatus status;
    if (override) {
      status = objectDb.put(txn.getTransaction(), key, data);
    } else {
      status = objectDb.putNoOverwrite(txn.getTransaction(), key, data);
    }
    final boolean didntExist = SUCCESS.equals(status);

    if (LOGGER.isLoggable(Level.FINER)) {
      if (didntExist) {
        LOGGER.finer("Key already exists in blob store, blob reused for id: " + id);
      }
    }
    return didntExist;
  }
コード例 #20
0
  @Test
  public void loadView() throws Exception {
    Mockito.when(securityClientMock.execute(Mockito.any(URL.class)))
        .thenReturn(
            IOUtils.toString(
                JenkinsRequestManagerTest.class.getResourceAsStream(
                    "JenkinsRequestManager_loadView.xml")));

    List<Job> actualJobs = requestManager.loadJenkinsView("http://myjenkins/");

    List<Job> expectedJobs = new LinkedList<Job>();

    expectedJobs.add(
        new JobBuilder()
            .job("sql-tools", "blue", "http://myjenkins/job/sql-tools/", "true")
            .lastBuild("http://myjenkins/job/sql-tools/15/", "15", SUCCESS.getStatus(), "false")
            .health("health-80plus", "0 tests en échec sur un total de 24 tests")
            .get());
    expectedJobs.add(
        new JobBuilder().job("db-utils", "grey", "http://myjenkins/job/db-utils/", "false").get());
    expectedJobs.add(
        new JobBuilder()
            .job("myapp", "red", "http://myjenkins/job/myapp/", "false")
            .lastBuild("http://myjenkins/job/myapp/12/", "12", FAILURE.getStatus(), "true")
            .health("health-00to19", "24 tests en échec sur un total de 24 tests")
            .parameter(
                "param1", "ChoiceParameterDefinition", "value1", "value1", "value2", "value3")
            .parameter("runIntegrationTest", "BooleanParameterDefinition", null)
            .get());
    expectedJobs.add(
        new JobBuilder()
            .job("swing-utils", "disabled", "http://myjenkins/job/swing-utils/", "true")
            .lastBuild("http://myjenkins/job/swing-utils/5/", "5", FAILURE.getStatus(), "false")
            .health("health20to39", "0 tests en échec sur un total de 24 tests")
            .parameter("dummyParam", null, null)
            .get());

    assertReflectionEquals(expectedJobs, actualJobs);
  }
コード例 #21
0
ファイル: QuoteStatus.java プロジェクト: 297513458/android
 public static boolean isSuccess(Integer status) {
   return status != null && SUCCESS.getValue() == status;
 }
コード例 #22
0
ファイル: ResponseData.java プロジェクト: ceoofworld/libqa
 public static <T> ResponseData<T> createSuccessResult(Number number) {
   return new ResponseData<>(SUCCESS.getCode(), SUCCESS.getComment(), number);
 }
コード例 #23
0
  /** This method isn't private solely to allow a unit test in the same package to call it */
  void scan() {

    try {
      scanLock.lockInterruptibly();
    } catch (InterruptedException ie) {
      Thread.currentThread().interrupt();
      return;
    }
    try {
      if (scanEnabled) { // confirm the scan is still wanted
        log.tracef(
            "Scanning directory %s for deployment content changes",
            deploymentDir.getAbsolutePath());

        List<ScannerTask> scannerTasks = new ArrayList<ScannerTask>();

        final Set<String> registeredDeployments = getDeploymentNames();
        final Set<String> toRemove = new HashSet<String>(deployed.keySet());
        scanDirectory(deploymentDir, scannerTasks, registeredDeployments, toRemove);

        // Add remove actions to the plan for anything we count as
        // deployed that we didn't find on the scan
        for (String missing : toRemove) {
          // TODO -- minor -- this assumes the deployment was in the root deploymentDir,
          // not a child dir, and therefore puts the '.undeploying' file there
          File parent = deploymentDir;
          scannerTasks.add(new UndeployTask(missing, parent));
        }

        if (scannerTasks.size() > 0) {
          List<ModelNode> updates = new ArrayList<ModelNode>(scannerTasks.size());

          for (ScannerTask task : scannerTasks) {
            final ModelNode update = task.getUpdate();
            if (log.isDebugEnabled()) {
              log.debugf("Deployment scan of [%s] found update action [%s]", deploymentDir, update);
            }
            updates.add(update);
          }

          while (!updates.isEmpty()) {
            ModelNode composite = getCompositeUpdate(updates);
            final ModelNode results =
                serverController.execute(OperationBuilder.Factory.create(composite).build());
            final List<Property> resultList = results.get(RESULT).asPropertyList();
            final List<ModelNode> toRetry = new ArrayList<ModelNode>();
            final List<ScannerTask> retryTasks = new ArrayList<ScannerTask>();
            for (int i = 0; i < resultList.size(); i++) {
              final ModelNode result = resultList.get(i).getValue();
              final ScannerTask task = scannerTasks.get(i);
              final ModelNode outcome = result.get(OUTCOME);
              if (outcome.isDefined() && SUCCESS.equals(outcome.asString())) {
                task.handleSuccessResult();
              } else if (outcome.isDefined() && CANCELLED.equals(outcome.asString())) {
                toRetry.add(updates.get(i));
                retryTasks.add(task);
              } else {
                task.handleFailureResult(result);
              }
            }
            updates = toRetry;
            scannerTasks = retryTasks;
          }
        }
        log.tracef("Scan complete");
      }
    } finally {
      scanLock.unlock();
    }
  }
コード例 #24
0
ファイル: ResponseData.java プロジェクト: ceoofworld/libqa
 public static <T> ResponseData<T> createSuccessResult(Iterable<T> data) {
   return new ResponseData<>(SUCCESS.getCode(), SUCCESS.getComment(), data);
 }
コード例 #25
0
 private TaskActivity createSuccess() {
   return new TaskActivity(SUCCESS.getValue(), TASK_ID, SUCCESS);
 }