Ejemplo n.º 1
0
 @Override
 protected void processMethod(StageMethod method) {
   switch (method.getStageMethod()) {
     case STAGEOP_PARSE_AND_EXECUTE:
       parseAndExecute(method);
       break;
     default:
       method.getRq().setError(ErrorType.INTERNAL_SERVER_ERROR, "unknown stage operation");
       master.requestFinished(method.getRq());
   }
 }
Ejemplo n.º 2
0
  protected static StatVFS getVolumeInfo(MRCRequestDispatcher master, StorageManager sMan)
      throws DatabaseException {

    final VolumeInfo volume = sMan.getVolumeInfo();
    final FileMetadata volumeRoot = sMan.getMetadata(1);

    int blockSize = sMan.getDefaultStripingPolicy(1).getStripeSize() * 1024;
    long bavail = master.getOSDStatusManager().getUsableSpace(volume.getId()) / blockSize;
    long bfree = master.getOSDStatusManager().getFreeSpace(volume.getId()) / blockSize;
    long blocks = master.getOSDStatusManager().getTotalSpace(volume.getId()) / blockSize;
    String volumeId = volume.getId();
    AccessControlPolicyType acPolId = AccessControlPolicyType.valueOf(volume.getAcPolicyId());
    StripingPolicy.Builder defaultStripingPolicy =
        Converter.stripingPolicyToStripingPolicy(sMan.getDefaultStripingPolicy(1));
    String volumeName = volume.getName();
    String owningGroupId = volumeRoot.getOwningGroupId();
    String ownerId = volumeRoot.getOwnerId();
    int perms = volumeRoot.getPerms();

    long newEtag = blockSize + bavail + blocks;

    return StatVFS.newBuilder()
        .setBsize(blockSize)
        .setBfree(bfree)
        .setBavail(bavail)
        .setBlocks(blocks)
        .setFsid(volumeId)
        .setNamemax(1024)
        .setOwnerUserId(ownerId)
        .setOwnerGroupId(owningGroupId)
        .setName(volumeName)
        .setEtag(newEtag)
        .setMode(perms)
        .setAccessControlPolicy(acPolId)
        .setDefaultStripingPolicy(defaultStripingPolicy)
        .build();
  }
Ejemplo n.º 3
0
  /**
   * Execute an operation
   *
   * @param operation MRCOperation to execute
   * @param method StageMethod to serve as the context
   */
  private void execute(MRCOperation op, StageMethod method) {
    final MRCRequest rq = method.getRq();
    final RPCServerRequest rpcRequest = rq.getRPCRequest();
    final RPCHeader header = rpcRequest.getHeader();
    final RPCHeader.RequestHeader rqHeader = header.getRequestHeader();

    try {

      if (Logging.isDebug()) {

        StringBuffer params = new StringBuffer();
        Map<FieldDescriptor, Object> fieldMap =
            rq.getRequestArgs() == null ? null : rq.getRequestArgs().getAllFields();
        if (fieldMap != null) {
          int i = 0;
          for (Entry<FieldDescriptor, Object> entry : fieldMap.entrySet()) {
            params.append(
                entry.getKey().getName()
                    + "='"
                    + entry.getValue()
                    + (i == fieldMap.size() - 1 ? "'" : "', "));
            i++;
          }
        }
        Logging.logMessage(
            Logging.LEVEL_DEBUG,
            this,
            "parsed request: %s (%s)\n",
            StatusPage.getOpName(rqHeader.getProcId()),
            params.toString());
      }

      op.startRequest(rq);

    } catch (UserException exc) {
      reportUserError(op, rq, exc, exc.getErrno());

    } catch (MRCException exc) {
      Throwable cause = exc.getCause();
      if (cause instanceof DatabaseException
          && ((DatabaseException) cause).getType() == ExceptionType.NOT_ALLOWED)
        reportUserError(op, rq, exc, POSIXErrno.POSIX_ERROR_EPERM);
      else reportServerError(op, rq, exc);

    } catch (DatabaseException exc) {
      if (exc.getType() == ExceptionType.NOT_ALLOWED) {
        reportUserError(op, rq, exc, POSIXErrno.POSIX_ERROR_EPERM);
      } else if (exc.getType() == ExceptionType.REDIRECT) {
        try {
          redirect(
              rq,
              exc.getAttachment() != null
                  ? (String) exc.getAttachment()
                  : master.getReplMasterUUID());
        } catch (MRCException e) {
          reportServerError(op, rq, e);
        }
      } else reportServerError(op, rq, exc);

    } catch (Throwable exc) {
      reportServerError(op, rq, exc);
    }
  }
Ejemplo n.º 4
0
  /**
   * Parse request and execute method
   *
   * @param method stagemethod to execute
   */
  private void parseAndExecute(StageMethod method) {

    final MRCRequest rq = method.getRq();
    final RPCServerRequest rpcRequest = rq.getRPCRequest();
    final RPCHeader header = rpcRequest.getHeader();
    final RPCHeader.RequestHeader rqHeader = header.getRequestHeader();

    if (header.getMessageType() != MessageType.RPC_REQUEST) {
      rq.setError(
          ErrorType.GARBAGE_ARGS,
          POSIXErrno.POSIX_ERROR_EIO,
          "expected RPC request message type but got " + header.getMessageType());
      return;
    }

    final MRCOperation op = operations.get(rqHeader.getProcId());

    if (op == null) {
      rq.setError(
          ErrorType.INVALID_PROC_ID,
          "requested operation (" + rqHeader.getProcId() + ") is not available on this MRC");
      master.requestFinished(rq);
      return;
    }

    if (Logging.isDebug())
      Logging.logMessage(
          Logging.LEVEL_DEBUG,
          Category.stage,
          this,
          "operation for request %s: %s",
          rq.toString(),
          op.getClass().getSimpleName());

    if (statisticsEnabled) {
      _opCountMap.put(rqHeader.getProcId(), _opCountMap.get(rqHeader.getProcId()) + 1);
    }

    // parse request arguments
    ErrorRecord error = op.parseRequestArgs(rq);
    if (error != null) {
      rq.setError(error);
      master.requestFinished(rq);
      return;
    }

    try {

      // get the auth data if available
      Auth auth =
          header.getRequestHeader().hasAuthData() ? header.getRequestHeader().getAuthData() : null;

      // get the user credentials
      org.xtreemfs.foundation.pbrpc.generatedinterfaces.RPC.UserCredentials ctx =
          op.getUserCredentials(rq);

      if (ctx != null)
        try {
          UserCredentials cred =
              master
                  .getAuthProvider()
                  .getEffectiveCredentials(ctx, rpcRequest.getConnection().getChannel());
          rq.getDetails().superUser = cred.isSuperUser();
          rq.getDetails().groupIds = cred.getGroupIDs();
          rq.getDetails().userId = cred.getUserID();
          rq.getDetails().auth = auth;
          rq.getDetails().password =
              auth != null && auth.hasAuthPasswd() ? auth.getAuthPasswd().getPassword() : "";
        } catch (AuthenticationException ex) {
          throw new UserException(POSIXErrno.POSIX_ERROR_EPERM, ex.getMessage());
        }

    } catch (Exception exc) {

      method
          .getRq()
          .setError(
              ErrorType.INTERNAL_SERVER_ERROR, "could not initialize authentication module", exc);
      master.requestFinished(method.getRq());
      return;
    }

    execute(op, method);
  }
Ejemplo n.º 5
0
 public RenewOperation(MRCRequestDispatcher master) {
   super(master);
   renewTimedOutCaps = master.getConfig().isRenewTimedOutCaps();
 }
Ejemplo n.º 6
0
  /**
   * Parse request and execute method
   *
   * @param method stagemethod to execute
   */
  private void parseAndExecute(StageMethod method) {

    final MRCRequest rq = method.getRq();
    final RPCServerRequest rpcRequest = rq.getRPCRequest();
    final RPCHeader header = rpcRequest.getHeader();
    final RPCHeader.RequestHeader rqHeader = header.getRequestHeader();

    if (header.getMessageType() != MessageType.RPC_REQUEST) {
      rq.setError(
          ErrorType.GARBAGE_ARGS,
          POSIXErrno.POSIX_ERROR_EIO,
          "expected RPC request message type but got " + header.getMessageType());
      return;
    }

    final MRCOperation op = operations.get(rqHeader.getProcId());

    if (op == null) {
      rq.setError(
          ErrorType.INVALID_PROC_ID,
          "requested operation (" + rqHeader.getProcId() + ") is not available on this MRC");
      master.requestFinished(rq);
      return;
    }

    if (Logging.isDebug())
      Logging.logMessage(
          Logging.LEVEL_DEBUG,
          Category.stage,
          this,
          "operation for request %s: %s",
          rq.toString(),
          op.getClass().getSimpleName());

    if (statisticsEnabled) {
      _opCountMap.put(rqHeader.getProcId(), _opCountMap.get(rqHeader.getProcId()) + 1);
    }

    // parse request arguments
    ErrorRecord error = op.parseRequestArgs(rq);
    if (error != null) {
      rq.setError(error);
      master.requestFinished(rq);
      return;
    }

    try {

      // get the auth data if available
      Auth auth =
          header.getRequestHeader().hasAuthData() ? header.getRequestHeader().getAuthData() : null;

      // get the user credentials
      org.xtreemfs.foundation.pbrpc.generatedinterfaces.RPC.UserCredentials ctx =
          op.getUserCredentials(rq);

      if (ctx != null)
        try {
          UserCredentials cred =
              master
                  .getAuthProvider()
                  .getEffectiveCredentials(ctx, rpcRequest.getConnection().getChannel());
          rq.getDetails().superUser = cred.isSuperUser();
          rq.getDetails().groupIds = cred.getGroupIDs();
          rq.getDetails().userId = cred.getUserID();
          rq.getDetails().auth = auth;
          rq.getDetails().password =
              auth != null && auth.hasAuthPasswd() ? auth.getAuthPasswd().getPassword() : "";
        } catch (AuthenticationException ex) {
          throw new UserException(POSIXErrno.POSIX_ERROR_EPERM, ex.getMessage());
        }

    } catch (Exception exc) {

      method
          .getRq()
          .setError(
              ErrorType.INTERNAL_SERVER_ERROR, "could not initialize authentication module", exc);
      master.requestFinished(method.getRq());
      return;
    }

    try {

      if (Logging.isDebug()) {

        StringBuffer params = new StringBuffer();
        Map<FieldDescriptor, Object> fieldMap =
            rq.getRequestArgs() == null ? null : rq.getRequestArgs().getAllFields();
        if (fieldMap != null) {
          int i = 0;
          for (Entry<FieldDescriptor, Object> entry : fieldMap.entrySet()) {
            params.append(
                entry.getKey().getName()
                    + "='"
                    + entry.getValue()
                    + (i == fieldMap.size() - 1 ? "'" : "', "));
            i++;
          }
        }
        Logging.logMessage(
            Logging.LEVEL_DEBUG,
            this,
            "parsed request: %s (%s)\n",
            StatusPage.getOpName(rqHeader.getProcId()),
            params.toString());
      }

      op.startRequest(rq);

    } catch (UserException exc) {
      reportUserError(op, rq, exc, exc.getErrno());

    } catch (MRCException exc) {
      Throwable cause = exc.getCause();
      if (cause instanceof DatabaseException
          && ((DatabaseException) cause).getType() == ExceptionType.NOT_ALLOWED)
        reportUserError(op, rq, exc, POSIXErrno.POSIX_ERROR_EPERM);
      else reportServerError(op, rq, exc);

    } catch (DatabaseException exc) {
      if (exc.getType() == ExceptionType.NOT_ALLOWED) {
        reportUserError(op, rq, exc, POSIXErrno.POSIX_ERROR_EPERM);
      } else if (exc.getType() == ExceptionType.REDIRECT) {
        try {
          redirect(
              rq,
              exc.getAttachment() != null
                  ? (String) exc.getAttachment()
                  : master.getReplMasterUUID());
        } catch (MRCException e) {
          reportServerError(op, rq, e);
        }
      } else reportServerError(op, rq, exc);

    } catch (Throwable exc) {
      reportServerError(op, rq, exc);
    }
  }
Ejemplo n.º 7
0
  public void shutdown() {
    Logging.logMessage(Logging.LEVEL_DEBUG, this, "shutting down testEnv...");

    if (enabledServs.contains(Services.MRC) && mrc != null) {
      try {
        mrc.shutdown();
      } catch (Throwable th) {
        th.printStackTrace();
      }
    }

    if (enabledServs.contains(Services.OSD)) {
      try {
        for (TestOSD osd : osds.values()) {
          if (osd != null && osd.started) {
            osd.shutdown();
          }
        }
      } catch (Throwable th) {
        th.printStackTrace();
      }
    }

    if (enabledServs.contains(Services.UUID_RESOLVER)) {
      try {
        UUIDResolver.shutdown();
      } catch (Throwable th) {
      }
    }

    if (enabledServs.contains(Services.DIR_SERVICE) && dirService != null) {
      try {
        dirService.shutdown();
        dirService.waitForShutdown();
      } catch (Throwable th) {
        th.printStackTrace();
      }
    }

    try {
      getRpcClient().shutdown();
      getRpcClient().waitForShutdown();
    } catch (Throwable th) {
      th.printStackTrace();
    }

    if (enabledServs.contains(Services.TIME_SYNC)) {
      try {
        tsInstance = TimeSync.getInstance();
        if (tsInstance != null) {
          tsInstance.shutdown();
          tsInstance.waitForShutdown();
        }
      } catch (Throwable th) {
      }
    }

    // cleanup
    File testDir = new File(SetupUtils.TEST_DIR);
    // FSUtils.delTree(testDir);
  }
Ejemplo n.º 8
0
  public void start() throws Exception {
    try {
      // ensure that TEST_DIR is empty
      File testDir = new File(SetupUtils.TEST_DIR);
      FSUtils.delTree(testDir);
      testDir.mkdirs();

      rpcClient = SetupUtils.createRPCClient(10000);
      getRpcClient().start();
      getRpcClient().waitForStartup();

      dirClient = SetupUtils.createDIRClient(getRpcClient());

      if (enabledServs.contains(Services.DIR_SERVICE)) {
        dirService =
            new DIRRequestDispatcher(SetupUtils.createDIRConfig(), SetupUtils.createDIRdbsConfig());
        dirService.startup();
        dirService.waitForStartup();
        Logging.logMessage(Logging.LEVEL_DEBUG, this, "DIR running");
      }

      if (enabledServs.contains(Services.TIME_SYNC) || enabledServs.contains(Services.MOCKUP_OSD)) {
        tsInstance = TimeSync.initializeLocal(50);
        tsInstance.waitForStartup();
      }

      if (enabledServs.contains(Services.UUID_RESOLVER)) {
        DIRClient dc =
            new DIRClient(dirClient, new InetSocketAddress[] {getDIRAddress()}, 10, 1000 * 5);
        UUIDResolver.start(dc, 1000, 10 * 10 * 1000);
        SetupUtils.localResolver();
      }

      if (enabledServs.contains(Services.MOCKUP_OSD)) {
        Map<String, String> dmap = new HashMap();
        dmap.put("free", "1000000000");
        dmap.put("total", "1000000000");
        dmap.put("load", "0");
        dmap.put("totalRAM", "1000000000");
        dmap.put("usedRAM", "0");
        dmap.put("proto_version", "" + OSDServiceConstants.INTERFACE_ID);
        Service reg =
            Service.newBuilder()
                .setType(ServiceType.SERVICE_TYPE_OSD)
                .setName("mockUpOSD")
                .setUuid("mockUpOSD")
                .setVersion(0)
                .setLastUpdatedS(0)
                .setData(ServiceDataMap.newBuilder().addAllData(KeyValuePairs.fromMap(dmap)))
                .build();
        RPCResponse<serviceRegisterResponse> response =
            dirClient.xtreemfs_service_register(
                null, RPCAuthentication.authNone, RPCAuthentication.userService, reg);
        response.get();
        response.freeBuffers();

        UUIDResolver.addLocalMapping("mockUpOSD", 11111, Schemes.SCHEME_PBRPC);
      }

      if (enabledServs.contains(Services.MOCKUP_OSD2)) {
        Map<String, String> dmap = new HashMap();
        dmap.put("free", "1000000000");
        dmap.put("total", "1000000000");
        dmap.put("load", "0");
        dmap.put("totalRAM", "1000000000");
        dmap.put("usedRAM", "0");
        dmap.put("proto_version", "" + OSDServiceConstants.INTERFACE_ID);
        Service reg =
            Service.newBuilder()
                .setType(ServiceType.SERVICE_TYPE_OSD)
                .setName("mockUpOSD2")
                .setUuid("mockUpOSD2")
                .setVersion(0)
                .setLastUpdatedS(0)
                .setData(ServiceDataMap.newBuilder().addAllData(KeyValuePairs.fromMap(dmap)))
                .build();
        RPCResponse<serviceRegisterResponse> response =
            dirClient.xtreemfs_service_register(
                null, RPCAuthentication.authNone, RPCAuthentication.userService, reg);
        response.get();
        response.freeBuffers();

        UUIDResolver.addLocalMapping("mockUpOSD2", 11111, Schemes.SCHEME_PBRPC);
      }

      if (enabledServs.contains(Services.MOCKUP_OSD3)) {
        Map<String, String> dmap = new HashMap();
        dmap.put("free", "1000000000");
        dmap.put("total", "1000000000");
        dmap.put("load", "0");
        dmap.put("totalRAM", "1000000000");
        dmap.put("usedRAM", "0");
        dmap.put("proto_version", "" + OSDServiceConstants.INTERFACE_ID);
        Service reg =
            Service.newBuilder()
                .setType(ServiceType.SERVICE_TYPE_OSD)
                .setName("mockUpOSD3")
                .setUuid("mockUpOSD3")
                .setVersion(0)
                .setLastUpdatedS(0)
                .setData(ServiceDataMap.newBuilder().addAllData(KeyValuePairs.fromMap(dmap)))
                .build();
        RPCResponse<serviceRegisterResponse> response =
            dirClient.xtreemfs_service_register(
                null, RPCAuthentication.authNone, RPCAuthentication.userService, reg);
        response.get();
        response.freeBuffers();

        UUIDResolver.addLocalMapping("mockUpOSD3", 11111, Schemes.SCHEME_PBRPC);
      }

      if (enabledServs.contains(Services.OSD)) {
        int osdCount = Collections.frequency(enabledServs, Services.OSD);
        osds = new HashMap<String, TestOSD>(osdCount);
        osdConfigs = SetupUtils.createMultipleOSDConfigs(osdCount);
        for (OSDConfig config : osdConfigs) {
          TestOSD osd = new TestOSD(new OSDRequestDispatcher(config));
          osd.start();
          osds.put(config.getUUID().toString(), osd);
        }

        // Save address of first OSD for getOSDAdress method.
        firstOSDAddress = osdConfigs[0].getUUID().getAddress();

        Logging.logMessage(Logging.LEVEL_DEBUG, this, "OSDs 1-" + osdCount + " running");
      }

      if (enabledServs.contains(Services.MRC)) {
        mrc =
            new MRCRequestDispatcher(
                SetupUtils.createMRC1Config(), SetupUtils.createMRC1dbsConfig());
        mrc.startup();
        Logging.logMessage(Logging.LEVEL_DEBUG, this, "MRC running");
      }

      if (enabledServs.contains(Services.MRC_CLIENT)) {
        mrcClient = new MRCServiceClient(rpcClient, null);
      }

      if (enabledServs.contains(Services.OSD_CLIENT)) {
        osdClient = new OSDServiceClient(rpcClient, null);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      // Shutdown servers which were already started or they will block ports.
      shutdown();

      // After shutdown, log remaining threads in case of blocked ports to debug the issue.
      if (ex instanceof BindException && ex.getMessage().contains("Address already in use")) {
        Logging.logMessage(
            Logging.LEVEL_ERROR,
            this,
            "TestEnvironment could not be started because: "
                + ex.getMessage()
                + " Please examine the following dump of threads to check if a previous test method did not correctly stop all servers.");
        StringBuilder threadStates = new StringBuilder();
        CrashReporter.reportThreadStates(threadStates);
        Logging.logMessage(Logging.LEVEL_ERROR, this, "Thread States: %s", threadStates.toString());
      }

      throw ex;
    }
  }