@Override public IndexedRecord getCurrent() throws NoSuchElementException { if (!startable || (advanceable != null && !advanceable)) { throw new NoSuchElementException(); } IndexedRecord record = new GenericData.Record(schema); record.put(0, current.getName()); return record; }
@Override public IndexedRecord getCurrent() throws NoSuchElementException { if (!startable || (advanceable != null && !advanceable)) { throw new NoSuchElementException(); } IndexedRecord record = new GenericData.Record(schema); record.put(0, current.getName()); return record; }
@Override public List<NamedThing> getSchemaNames(RuntimeContainer container) throws IOException { List<NamedThing> result = new ArrayList<>(); try { CloudQueueClient client = getStorageQueueClient(container); for (CloudQueue q : client.listQueues()) { result.add(new SimpleNamedThing(q.getName(), q.getName())); } } catch (InvalidKeyException | URISyntaxException e) { throw new ComponentException(e); } return result; }
@Override public List<NamedThing> getSchemaNames(RuntimeContainer container) throws IOException { List<NamedThing> result = new ArrayList<>(); try { CloudQueueClient client = getStorageQueueClient(container); for (CloudQueue q : client.listQueues()) { result.add(new SimpleNamedThing(q.getName(), q.getName())); } } catch (InvalidKeyException | URISyntaxException e) { throw new ComponentException(e); } return result; }
/** * Returns the canonical name for shared access. * * @return the canonical name for shared access. */ private String getSharedAccessCanonicalName() { String accountName = this.getServiceClient().getCredentials().getAccountName(); String queueName = this.getName(); return String.format("/%s/%s/%s", SR.QUEUE, accountName, queueName); }
/** * Returns the canonical name for shared access. * * @return the canonical name for shared access. */ private String getSharedAccessCanonicalName() { String accountName = this.getServiceClient().getCredentials().getAccountName(); String queueName = this.getName(); return String.format("/%s/%s/%s", SR.QUEUE, accountName, queueName); }
/** * This method create a queue if it doesn't exist */ public boolean createQueueIfNotExists(String queueName) throws InvalidKeyException, URISyntaxException, StorageException { CloudQueueClient client = connection.getCloudStorageAccount().createCloudQueueClient(); CloudQueue queueRef = client.getQueueReference(queueName); boolean creationResult; try { creationResult = queueRef.createIfNotExists(null, AzureStorageUtils.getTalendOperationContext()); } catch (StorageException e) { if (!e.getErrorCode().equals(StorageErrorCodeStrings.QUEUE_BEING_DELETED)) { throw e; } LOGGER.warn(messages.getMessage("error.QueueDeleted", queueRef.getName())); // Documentation doesn't specify how many seconds at least to wait. // 40 seconds before retrying. // See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/delete-queue3 try { Thread.sleep(40000); } catch (InterruptedException eint) { throw new RuntimeException(messages.getMessage("error.InterruptedException")); } creationResult = queueRef.createIfNotExists(null, AzureStorageUtils.getTalendOperationContext()); LOGGER.debug(messages.getMessage("debug.QueueCreated", queueRef.getName())); } return creationResult; }
/** * This method create a queue if it doesn't exist */ public boolean createQueueIfNotExists(String queueName) throws InvalidKeyException, URISyntaxException, StorageException { CloudQueueClient client = connection.getCloudStorageAccount().createCloudQueueClient(); CloudQueue queueRef = client.getQueueReference(queueName); boolean creationResult; try { creationResult = queueRef.createIfNotExists(null, AzureStorageUtils.getTalendOperationContext()); } catch (StorageException e) { if (!e.getErrorCode().equals(StorageErrorCodeStrings.QUEUE_BEING_DELETED)) { throw e; } LOGGER.warn(messages.getMessage("error.QueueDeleted", queueRef.getName())); // Documentation doesn't specify how many seconds at least to wait. // 40 seconds before retrying. // See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/delete-queue3 try { Thread.sleep(40000); } catch (InterruptedException eint) { throw new RuntimeException(messages.getMessage("error.InterruptedException")); } creationResult = queueRef.createIfNotExists(null, AzureStorageUtils.getTalendOperationContext()); LOGGER.debug(messages.getMessage("debug.QueueCreated", queueRef.getName())); } return creationResult; }
@NotNull public List<Queue> getQueues(@NotNull StorageAccount storageAccount) throws AzureCmdException { List<Queue> qList = new ArrayList<Queue>(); try { CloudQueueClient client = getCloudQueueClient(storageAccount); for (CloudQueue cloudQueue : client.listQueues(null, QueueListingDetails.ALL, null, null)) { String uri = cloudQueue.getUri() != null ? cloudQueue.getUri().toString() : ""; qList.add(new Queue(Strings.nullToEmpty(cloudQueue.getName()), uri, cloudQueue.getApproximateMessageCount())); } return qList; } catch (Throwable t) { throw new AzureCmdException("Error retrieving the Queue list", t); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testUploadMetadataClearExisting() throws URISyntaxException, StorageException { CloudQueue queueForGet = this.queue.getServiceClient().getQueueReference(this.queue.getName()); HashMap<String, String> metadata1 = new HashMap<String, String>(); String key = "ExistingMetadata1" + UUID.randomUUID().toString().replace("-", ""); metadata1.put(key, "ExistingMetadataValue1"); this.queue.setMetadata(metadata1); queueForGet.downloadAttributes(); assertFalse(queueForGet.getMetadata().containsKey(key)); HashMap<String, String> metadata2 = new HashMap<String, String>(); this.queue.setMetadata(metadata2); this.queue.uploadMetadata(); queueForGet.downloadAttributes(); assertTrue(queueForGet.getMetadata().size() == 0); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testSASClientParse() throws StorageException, InvalidKeyException, URISyntaxException { // Add a policy, check setting and getting. SharedAccessQueuePolicy policy1 = new SharedAccessQueuePolicy(); Calendar now = GregorianCalendar.getInstance(); now.add(Calendar.MINUTE, -15); policy1.setSharedAccessStartTime(now.getTime()); now.add(Calendar.MINUTE, 30); policy1.setSharedAccessExpiryTime(now.getTime()); policy1.setPermissions(EnumSet.of(SharedAccessQueuePermissions.READ, SharedAccessQueuePermissions.PROCESSMESSAGES, SharedAccessQueuePermissions.ADD, SharedAccessQueuePermissions.UPDATE)); String sasString = this.queue.generateSharedAccessSignature(policy1, null); URI queueUri = new URI("http://myaccount.queue.core.windows.net/myqueue"); CloudQueueClient queueClient1 = new CloudQueueClient(new URI("http://myaccount.queue.core.windows.net/"), new StorageCredentialsSharedAccessSignature(sasString)); CloudQueue queue1 = new CloudQueue(queueUri, queueClient1.getCredentials()); queue1.getName(); CloudQueueClient queueClient2 = new CloudQueueClient(new URI("http://myaccount.queue.core.windows.net/"), new StorageCredentialsSharedAccessSignature(sasString)); CloudQueue queue2 = new CloudQueue(queueUri, queueClient2.getCredentials()); queue2.getName(); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testUploadMetadataNullInput() throws URISyntaxException, StorageException { CloudQueue queueForGet = this.queue.getServiceClient().getQueueReference(this.queue.getName()); HashMap<String, String> metadata1 = new HashMap<String, String>(); String key = "ExistingMetadata1" + UUID.randomUUID().toString().replace("-", ""); metadata1.put(key, "ExistingMetadataValue1"); this.queue.setMetadata(metadata1); queueForGet.downloadAttributes(); assertFalse(queueForGet.getMetadata().containsKey(key)); this.queue.uploadMetadata(); queueForGet.downloadAttributes(); assertTrue(queueForGet.getMetadata().containsKey(key)); this.queue.setMetadata(null); this.queue.uploadMetadata(); queueForGet.downloadAttributes(); assertTrue(queueForGet.getMetadata().size() == 0); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testUploadMetadata() throws URISyntaxException, StorageException { CloudQueue queueForGet = this.queue.getServiceClient().getQueueReference(this.queue.getName()); HashMap<String, String> metadata1 = new HashMap<String, String>(); metadata1.put("ExistingMetadata1", "ExistingMetadataValue1"); this.queue.setMetadata(metadata1); queueForGet.downloadAttributes(); assertFalse(queueForGet.getMetadata().containsKey("ExistingMetadata1")); this.queue.uploadMetadata(); queueForGet.downloadAttributes(); assertTrue(queueForGet.getMetadata().containsKey("ExistingMetadata1")); }
CloudQueue q = qClient.getQueueReference(prefix + "a" + i); HashMap<String, String> metadata2 = new HashMap<String, String>(); metadata2.put("tags", q.getName()); q.setMetadata(metadata2); q.create(); for (CloudQueue queue : qClient.listQueues(prefix + "a", QueueListingDetails.METADATA, null, null)) { count++; assertTrue(queue.getMetadata().size() == 1 && queue.getMetadata().get("tags").equals(queue.getName()));
@Test public void testQueueClientConstructor() throws URISyntaxException, StorageException { final CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final String queueName = QueueTestHelper.generateRandomQueueName(); CloudQueue queue1 = qClient.getQueueReference(queueName); assertEquals(queueName, queue1.getName()); assertTrue(queue1.getUri().toString().endsWith(queueName)); assertEquals(qClient, queue1.getServiceClient()); CloudQueue queue2 = new CloudQueue(new URI(QueueTestHelper.appendQueueName(qClient.getEndpoint(), queueName)), qClient.getCredentials()); assertEquals(queueName, queue2.getName()); assertEquals(qClient.getCredentials(), queue2.getServiceClient().getCredentials()); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testQueueDownloadAttributes() throws StorageException, URISyntaxException { final CloudQueueMessage message1 = new CloudQueueMessage("messagetest1"); this.queue.addMessage(message1); final CloudQueueMessage message2 = new CloudQueueMessage("messagetest2"); this.queue.addMessage(message2); final HashMap<String, String> metadata = new HashMap<String, String>(5); int sum = 5; for (int i = 0; i < sum; i++) { metadata.put("key" + i, "value" + i); } this.queue.setMetadata(metadata); this.queue.uploadMetadata(); CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final CloudQueue queue2 = qClient.getQueueReference(this.queue.getName()); queue2.downloadAttributes(); assertEquals(sum, queue2.getMetadata().size()); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testQueueCreateIfNotExistsAfterCreate() throws URISyntaxException, StorageException { final CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final String queueName = QueueTestHelper.generateRandomQueueName(); CloudQueue queue = qClient.getQueueReference(queueName); assertEquals(queueName, queue.getName()); try { OperationContext createQueueContext1 = new OperationContext(); assertTrue(queue.createIfNotExists(null, createQueueContext1)); OperationContext createQueueContext2 = new OperationContext(); assertFalse(queue.createIfNotExists(null, createQueueContext2)); } finally { queue.deleteIfExists(); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testQueueCreateIfNotExists() throws URISyntaxException, StorageException { final CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final String queueName = QueueTestHelper.generateRandomQueueName(); CloudQueue queue = qClient.getQueueReference(queueName); assertEquals(queueName, queue.getName()); try { OperationContext createQueueContext = new OperationContext(); assertTrue(queue.createIfNotExists(null, createQueueContext)); assertEquals(createQueueContext.getLastResult().getStatusCode(), HttpURLConnection.HTTP_CREATED); assertFalse(queue.createIfNotExists()); } finally { queue.deleteIfExists(); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testQueueCreateAlreadyExists() throws URISyntaxException, StorageException { final CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final String queueName = QueueTestHelper.generateRandomQueueName(); CloudQueue queue = qClient.getQueueReference(queueName); assertEquals(queueName, queue.getName()); try { OperationContext createQueueContext1 = new OperationContext(); queue.create(null, createQueueContext1); assertEquals(createQueueContext1.getLastResult().getStatusCode(), HttpURLConnection.HTTP_CREATED); OperationContext createQueueContext2 = new OperationContext(); queue.create(null, createQueueContext2); assertEquals(createQueueContext2.getLastResult().getStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); } finally { queue.deleteIfExists(); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testQueueDelete() throws URISyntaxException, StorageException { final CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final String queueName = QueueTestHelper.generateRandomQueueName(); CloudQueue queue = qClient.getQueueReference(queueName); assertEquals(queueName, queue.getName()); try { OperationContext createQueueContext = new OperationContext(); queue.create(null, createQueueContext); assertEquals(createQueueContext.getLastResult().getStatusCode(), HttpURLConnection.HTTP_CREATED); OperationContext deleteQueueContext = new OperationContext(); queue.delete(null, deleteQueueContext); assertEquals(deleteQueueContext.getLastResult().getStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); try { queue.downloadAttributes(); fail(); } catch (StorageException ex) { assertEquals("Expected 404 Exception", ex.getHttpStatusCode(), HttpURLConnection.HTTP_NOT_FOUND); } } finally { queue.deleteIfExists(); } }