예제 #1
0
  private void removePhotoImp(String path)
      throws StorageException, URISyntaxException, IOException {

    splitter(path);
    createStorageAccount();
    container = serviceClient.getContainerReference(containerName);
    blob = container.getBlockBlobReference(blobName);
    blob.delete();
  }
예제 #2
0
  //    public static void main(String[] args) {
  //
  //        DataRepoImpl dataRepo = new DataRepoImpl();
  //
  //// -------------  LIST ALL ALBUMS -------------------------------
  ////        List<Album> allAlbums;
  ////        allAlbums = dataRepo.listAlbums();
  ////
  ////        for (Album album : allAlbums) {
  ////            dataRepo.printAlbumInfo(album);
  ////        }
  //// ---------------------------------------------------------------
  //
  //
  ////        -----------------------DELETE THE TABLE "LAST" ----------------------------
  ////        CloudTableClient tableClient = dataRepo.getTableClient ();
  ////        try {
  ////        CloudTable table =
  ////                tableClient.getTableReference("last");
  ////        table.deleteIfExists();
  ////            System.out.println("Deleted the table successfully!");
  ////        }
  ////        catch (URISyntaxException e)
  ////        {
  ////            System.out.println("URISyntaxException: " + e.getClass() + e.getMessage());
  ////        }
  ////        catch (StorageException e)
  ////        {
  ////            System.out.println("StorageException: " + e.getClass() + e.getMessage());
  ////        }
  ////        catch (Exception e)
  ////        {
  ////            System.out.println("Other type of exception: " + e.getClass() + e.getMessage());
  ////        }
  ////        ------------------------------------------------------------------------------
  //
  //
  //// ----------------- INSERT AN ALBUM -----------------------------
  ////        Album randomAlbum = dataRepo.getRandomAlbum();
  ////
  ////        dataRepo.printAlbumInfo(randomAlbum);
  ////        System.out.println("\n");
  ////
  ////        dataRepo.insertAlbum(randomAlbum);
  ////
  //
  //// ------------------------------------------------------------------
  //
  ////        Album insertedAlbum = dataRepo.retrieveAlbum(randomAlbum.getUniqueKey(),
  // this.tableName);
  ////        System.out.println("\n");
  ////        dataRepo.printAlbumInfo(insertedAlbum);
  ////
  //// -------------  LIST ALL ALBUMS -------------------------------
  ////        List<Album> allAlbums;
  ////        allAlbums = dataRepo.listAlbums();
  ////
  ////        for (Album album : allAlbums) {
  ////            dataRepo.printAlbumInfo(album);
  ////        }
  //// ---------------------------------------------------------------
  //
  //// --------------- REMOVE A SPECIFIC ALBUM -------------------------
  ////        try {
  ////        dataRepo.removeAlbum("19025e81-b140-4931-872a-f5ba6eb45fef");
  ////        dataRepo.removeAlbum("1e0e3a49-84a8-4976-baeb-285f6a2b166e");
  ////        dataRepo.removeAlbum("8fa93b0f-109a-4a4c-b117-d8db5521ca29");
  ////        dataRepo.removeAlbum("8e423497-ba16-401b-897c-e9ae8b1b69f2");
  ////        } catch (Exception e) {
  ////            System.out.print("Exception encountered:\n");
  ////            System.out.println("Exception class: " + e.getClass() + "\nException message: " +
  // e.getMessage() + "\nStack trace: " + e.getStackTrace());
  ////        }
  ////
  ////        System.out.println("Album removed successfully. \n");
  //// ------------------------------------------------------------------
  //
  ////        allAlbums = dataRepo.listAlbums();
  ////
  ////        for (Album album : allAlbums) {
  ////            dataRepo.printAlbumInfo(album);
  ////        }
  //
  //
  //// -------------------- RETRIEVE A SPECIFIC ALBUM --------------------
  //
  ////        Album retrievedAlbum = dataRepo.retrieveAlbum("656b138d-f0db-4c2f-9c60-4bbeb6706bdc",
  // this.tableName);
  ////        dataRepo.printAlbumInfo(retrievedAlbum);
  //// ------------------------------------------------------------------
  //
  //// ---------------- LIST ALL ALBUMS -------------------------------
  ////        allAlbums = dataRepo.listAlbums();
  ////        for (Album album : allAlbums) {
  ////            dataRepo.printAlbumInfo(album);
  ////        }
  //// ------------------------------------------------------------------
  //
  //
  //
  //    }
  private String savePhotoImpl(File file)
      throws StorageException, URISyntaxException, IOException, FileNotFoundException {
    if (file == null || !file.exists()) {
      throw new FileNotFoundException("Image file not exists!");
    }

    createStorageAccount();
    container = serviceClient.getContainerReference("album");
    container.createIfNotExist();
    setContainerPermission();
    String blockBlobReference = file.getName();
    // String filePath= file.getAbsolutePath();
    blob = container.getBlockBlobReference(blockBlobReference);
    // File fileReference = new File (filePath);
    blob.upload(new FileInputStream(file), file.length());

    String savedBlobPath = blob.getUri().toString();
    return savedBlobPath;
  }
  /*
   *
   * 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 ");
  }