public TenantBlobSizeProcessor() throws InvalidKeyException, URISyntaxException {
   // task-queue which is shared between processor and generator.
   super(
       new TenantBlobSizeQueue(
           SchedulerSettings.BlobStorageSizeQueue,
           StorageClientUtility.getCloudStorageAccount().createCloudQueueClient()));
 }
 public TenantDBBandwidthGenerator() throws InvalidKeyException, URISyntaxException {
   // tenantdbbandwidthqueue which is shared between processor and generator.
   super(
       new TenantDBBandwidthQueue(
           SchedulerSettings.DBBandwidthQueue,
           StorageClientUtility.getCloudStorageAccount().createCloudQueueClient()));
 }
  /*
   *
   * Delete Blobs for purged logs
   *
   * */
  private void deletePurgedTomcatLogs() {

    LOGGER.info("Start of method deletePurgedTomcatLogs ");
    CloudStorageAccount cloudAcc = StorageClientUtility.getDiagnosticCloudStorageAccount();
    CloudBlobClient blobClient = cloudAcc.createCloudBlobClient();
    CloudBlobContainer container;
    int deletedLogs = 0;
    Date lastProcessedTime = null;

    try {
      container = blobClient.getContainerReference(SchedulerSettings.WebTomcatLogsContainer);
      for (ListBlobItem item : container.listBlobs("", true, null, null, null)) {
        CloudBlob blob = container.getBlockBlobReference(item.getUri().toString());
        blob.downloadAttributes();
        Date latestModifiedDate = blob.getProperties().getLastModified();

        // Check  date stamp from WebLogMeteringBatch
        List<WebLogMeteringBatch> webLogMeteringBatchList =
            webLogMeteringBatchService.getMeteringBatchServiceDetails(item.getUri().toString());
        // Set lastProcessedTime to largest LastUpdatedTime
        if (!webLogMeteringBatchList.isEmpty()) {
          lastProcessedTime =
              webLogMeteringBatchList.get(webLogMeteringBatchList.size() - 1).getLastUpdatedTime();
        } else {
          lastProcessedTime = CommonUtility.getDate(CommonUtility.MIN_DATE);
        }

        if (latestModifiedDate.getTime() <= lastProcessedTime.getTime()) {
          // Delete Logs
          blob.delete();
          deletedLogs++;
          LOGGER.debug("Deleted BLOB :" + blob.getUri().toString());
        }
      }
      LOGGER.debug("Total DeletedLogs :" + deletedLogs);

    } catch (URISyntaxException e) {
      LOGGER.error("URISyntaxException ", e);
    } catch (StorageException e) {
      LOGGER.error("StorageException", e);
    }
    LOGGER.info("End of method deletePurgedTomcatLogs ");
  }
  /*
   *
   * Delete Entities from Diagnostic table
   *
   * @param String : Diagnostic Table name
   *
   *
   * */
  private void deleteDiagnosticTableEntities(String tableName) {
    LOGGER.info("Start of method deleteDiagnosticTableEntities ");
    try {
      TableStorageClient tableClient =
          TableStorageClient.create(
              false,
              StorageClientUtility.getDiagnosticAccName(),
              StorageClientUtility.getDiagnosticAccKey());

      ITable diagnstTable = tableClient.getTableReference(tableName);

      if (diagnstTable.isTableExist()) {
        LOGGER.info("Diagnostic Table exists : " + diagnstTable.getTableName());

        TableServiceContext context = diagnstTable.getTableServiceContext();

        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        long retentionTime =
            cal.getTimeInMillis() - SchedulerSettings.DiagnosticsTablesRetentionPeriod;
        long ticks = SchedulerSettings.TicksConversionConstant + (retentionTime * 10000);

        CloudTableQuery query = new CloudTableQuery();
        query.le("PartitionKey", "0" + ticks);

        // WADPerformanceCountersTable
        if (tableName.equalsIgnoreCase(DiagnosticsTables.WADPerformanceCountersTable.name())) {
          LOGGER.info("Start of Deletion of  WADPerformanceCountersTable");
          int deletedRows = 0;
          while (!context.retrieveEntities(query, PerfCounterEntity.class).isEmpty()) {
            List<ITableServiceEntity> listEntities =
                context.retrieveEntities(query, PerfCounterEntity.class);
            PerfCounterEntity[] perfArr = new PerfCounterEntity[listEntities.size()];
            perfArr = listEntities.toArray(perfArr);
            LOGGER.debug("WADPerformanceCountersTable: List size :" + perfArr.length);
            if (perfArr.length > 0) {
              for (PerfCounterEntity entity : perfArr) {
                // Delete Entity
                context.deleteEntity(entity);
                deletedRows++;
                LOGGER.debug("Deleting rows WADPerformanceCountersTable: Rownum :" + deletedRows);
              }
            }
          }
          LOGGER.debug("Total Rows Deleted for WADPerformanceCountersTable:" + deletedRows);
          LOGGER.info("End of Deletion of  WADPerformanceCountersTable");
        }
        // WADLogsTable
        else if (tableName.equalsIgnoreCase(DiagnosticsTables.WADLogsTable.name())) {
          LOGGER.info("Start of Deletion of  WADLogsTable");
          int deletedRows = 0;
          while (!context.retrieveEntities(query, WADLogsTableEntity.class).isEmpty()) {
            List<ITableServiceEntity> listEntities =
                context.retrieveEntities(query, WADLogsTableEntity.class);
            WADLogsTableEntity[] wadLogsfArr = new WADLogsTableEntity[listEntities.size()];
            wadLogsfArr = listEntities.toArray(wadLogsfArr);
            LOGGER.debug("WADLogsTable:  List size :" + wadLogsfArr.length);
            if (wadLogsfArr.length > 0) {
              for (WADLogsTableEntity entity : wadLogsfArr) {
                // Delete Entity
                context.deleteEntity(entity);
                deletedRows++;
                LOGGER.debug("Deleting rows WADLogsTable : Rownum :" + deletedRows);
              }
            }
          }
          LOGGER.debug("Total Rows Deleted for WADLogsTable:" + deletedRows);
          LOGGER.info("End of Deletion of  WADLogsTable");
        }
        // WADDirectoriesTable
        else if (tableName.equalsIgnoreCase(DiagnosticsTables.WADDirectoriesTable.name())) {
          LOGGER.info("Start of Deletion of  WADDirectoriesTable");
          int deletedRows = 0;
          while (!context.retrieveEntities(query, WADDirectoriesTableEntity.class).isEmpty()) {
            List<ITableServiceEntity> listEntities =
                context.retrieveEntities(query, WADDirectoriesTableEntity.class);
            WADDirectoriesTableEntity[] wadDirArr =
                new WADDirectoriesTableEntity[listEntities.size()];
            wadDirArr = listEntities.toArray(wadDirArr);
            LOGGER.debug(" WADDirectoriesTable: List size :" + wadDirArr.length);
            if (wadDirArr.length > 0) {
              for (WADDirectoriesTableEntity entity : wadDirArr) {
                // Delete Entity
                context.deleteEntity(entity);
                deletedRows++;
                LOGGER.debug("Deleting rows WADDirectoriesTable : Rownum :" + deletedRows);
              }
            }
          }
          LOGGER.debug("Total Rows Deleted for WADDirectoriesTable:" + deletedRows);
          LOGGER.info("End of Deletion of  WADDirectoriesTable");
        }
      } else {
        LOGGER.debug("Diagnostic Table : " + diagnstTable.getTableName() + " does not exist");
      }
    } catch (Exception e) {
      LOGGER.error(e.getMessage(), e);
    }
    LOGGER.info("End of method deleteDiagnosticTableEntities ");
  }
 public TenantCreationTask() throws InvalidKeyException, URISyntaxException {
   super(
       new TenantCreationQueue(
           SchedulerSettings.TenantCreationQueue,
           StorageClientUtility.getCloudStorageAccount().createCloudQueueClient()));
 }