コード例 #1
0
ファイル: MRCStatusManager.java プロジェクト: 2510/xtreemfs
  public synchronized void evaluateResponse(ServiceSet.Builder knownMRCs) {

    if (Logging.isDebug())
      Logging.logMessage(Logging.LEVEL_DEBUG, Category.misc, this, "response...");

    assert (knownMRCs != null);
    assert (knownMRCs.getServicesCount() != 0);

    if (Logging.isDebug()) {

      Logging.logMessage(Logging.LEVEL_DEBUG, Category.misc, this, "registered MRCs");
      for (Service mrc : knownMRCs.getServicesList()) {
        Logging.logMessage(Logging.LEVEL_DEBUG, Category.misc, this, "%s", mrc.getUuid());
      }
    }

    // update the list
    this.knownMRCs = knownMRCs;
    mrcAddrMap.clear();
    for (Service mrc : knownMRCs.getServicesList()) {
      String endpoint = KeyValuePairs.getValue(mrc.getData().getDataList(), "babudbReplAddr");
      if (endpoint != null) {
        int index = endpoint.indexOf(':');
        if (index != -1)
          mrcAddrMap.put(
              new InetSocketAddress(
                  endpoint.substring(0, index), Integer.parseInt(endpoint.substring(index + 1))),
              mrc.getUuid());
      }
    }
  }
コード例 #2
0
ファイル: TestEnvironment.java プロジェクト: 2510/xtreemfs
  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;
    }
  }