public void init()

in s3/src/main/java/site/ycsb/db/S3Client.java [128:240]


  public void init() throws DBException {
    final int count = INIT_COUNT.incrementAndGet();
    synchronized (S3Client.class){
      Properties propsCL = getProperties();
      int recordcount = Integer.parseInt(
          propsCL.getProperty("recordcount"));
      int operationcount = Integer.parseInt(
          propsCL.getProperty("operationcount"));
      int numberOfOperations = 0;
      if (recordcount > 0){
        if (recordcount > operationcount){
          numberOfOperations = recordcount;
        } else {
          numberOfOperations = operationcount;
        }
      } else {
        numberOfOperations = operationcount;
      }
      if (count <= numberOfOperations) {
        String accessKeyId = null;
        String secretKey = null;
        String endPoint = null;
        String region = null;
        String maxErrorRetry = null;
        String maxConnections = null;
        String protocol = null;
        BasicAWSCredentials s3Credentials;
        ClientConfiguration clientConfig;
        if (s3Client != null) {
          System.out.println("Reusing the same client");
          return;
        }
        try {
          InputStream propFile = S3Client.class.getClassLoader()
              .getResourceAsStream("s3.properties");
          Properties props = new Properties(System.getProperties());
          props.load(propFile);
          accessKeyId = props.getProperty("s3.accessKeyId");
          if (accessKeyId == null){
            accessKeyId = propsCL.getProperty("s3.accessKeyId");
          }
          System.out.println(accessKeyId);
          secretKey = props.getProperty("s3.secretKey");
          if (secretKey == null){
            secretKey = propsCL.getProperty("s3.secretKey");
          }
          System.out.println(secretKey);
          endPoint = props.getProperty("s3.endPoint");
          if (endPoint == null){
            endPoint = propsCL.getProperty("s3.endPoint", "s3.amazonaws.com");
          }
          System.out.println(endPoint);
          region = props.getProperty("s3.region");
          if (region == null){
            region = propsCL.getProperty("s3.region", "us-east-1");
          }
          System.out.println(region);
          maxErrorRetry = props.getProperty("s3.maxErrorRetry");
          if (maxErrorRetry == null){
            maxErrorRetry = propsCL.getProperty("s3.maxErrorRetry", "15");
          }
          maxConnections = props.getProperty("s3.maxConnections");
          if (maxConnections == null){
            maxConnections = propsCL.getProperty("s3.maxConnections");
          }
          protocol = props.getProperty("s3.protocol");
          if (protocol == null){
            protocol = propsCL.getProperty("s3.protocol", "HTTPS");
          }
          sse = props.getProperty("s3.sse");
          if (sse == null){
            sse = propsCL.getProperty("s3.sse", "false");
          }
          String ssec = props.getProperty("s3.ssec");
          if (ssec == null){
            ssec = propsCL.getProperty("s3.ssec", null);
          } else {
            ssecKey = new SSECustomerKey(ssec);
          }
        } catch (Exception e){
          System.err.println("The file properties doesn't exist "+e.toString());
          e.printStackTrace();
        }
        try {
          System.out.println("Inizializing the S3 connection");
          s3Credentials = new BasicAWSCredentials(accessKeyId, secretKey);
          clientConfig = new ClientConfiguration();
          clientConfig.setMaxErrorRetry(Integer.parseInt(maxErrorRetry));
          if(protocol.equals("HTTP")) {
            clientConfig.setProtocol(Protocol.HTTP);
          } else {
            clientConfig.setProtocol(Protocol.HTTPS);
          }
          if(maxConnections != null) {
            clientConfig.setMaxConnections(Integer.parseInt(maxConnections));
          }
          s3Client = new AmazonS3Client(s3Credentials, clientConfig);
          s3Client.setRegion(Region.getRegion(Regions.fromName(region)));
          s3Client.setEndpoint(endPoint);
          System.out.println("Connection successfully initialized");
        } catch (Exception e){
          System.err.println("Could not connect to S3 storage: "+ e.toString());
          e.printStackTrace();
          throw new DBException(e);
        }
      } else {
        System.err.println(
            "The number of threads must be less or equal than the operations");
        throw new DBException(new Error(
            "The number of threads must be less or equal than the operations"));
      }
    }
  }