Search in sources :

Example 11 with TAzureStorageConnectionProperties

use of org.talend.components.azurestorage.tazurestorageconnection.TAzureStorageConnectionProperties in project components by Talend.

the class AzureStorageTableWriterTest method setUp.

@Before
public void setUp() throws Exception {
    container = new RuntimeContainerMock();
    sink = new AzureStorageTableSink();
    properties = new TAzureStorageOutputTableProperties(PROP_ + "InputTable");
    properties.setupProperties();
    // valid fake connection
    properties.connection = new TAzureStorageConnectionProperties(PROP_ + "Connection");
    properties.connection.protocol.setValue(Protocol.HTTP);
    properties.connection.accountName.setValue("fakeAccountName");
    properties.connection.accountKey.setValue("fakeAccountKey=ANBHFYRJJFHRIKKJFU");
    properties.dieOnError.setValue(false);
    properties.tableName.setValue(TableHelper.generateRandomTableName());
    properties.actionOnTable.setValue(ActionOnTable.Create_table_if_does_not_exist);
    properties.actionOnData.setValue(ActionOnData.Insert);
    properties.schema.schema.setValue(TableHelper.getWriteSchema());
    properties.schemaReject.schema.setValue(TableHelper.getRejectSchema());
    properties.partitionKey.setStoredValue("PartitionKey");
    properties.rowKey.setStoredValue("RowKey");
}
Also used : TAzureStorageOutputTableProperties(org.talend.components.azurestorage.table.tazurestorageoutputtable.TAzureStorageOutputTableProperties) RuntimeContainerMock(org.talend.components.azurestorage.RuntimeContainerMock) TAzureStorageConnectionProperties(org.talend.components.azurestorage.tazurestorageconnection.TAzureStorageConnectionProperties)

Example 12 with TAzureStorageConnectionProperties

use of org.talend.components.azurestorage.tazurestorageconnection.TAzureStorageConnectionProperties in project components by Talend.

the class AzureStorageComponentListPropertiesTest method testSetConnection.

/**
 * @see org.talend.components.azurestorage.wizard.AzureStorageComponentListProperties#setConnection(TAzureStorageConnectionProperties)
 */
@Test
public void testSetConnection() {
    TAzureStorageConnectionProperties connection = new TAzureStorageConnectionProperties(null);
    AzureStorageComponentListProperties result = properties.setConnection(connection);
    assertNotNull("result cannot be null", result.getConnectionProperties());
}
Also used : TAzureStorageConnectionProperties(org.talend.components.azurestorage.tazurestorageconnection.TAzureStorageConnectionProperties) Test(org.junit.Test)

Example 13 with TAzureStorageConnectionProperties

use of org.talend.components.azurestorage.tazurestorageconnection.TAzureStorageConnectionProperties in project components by Talend.

the class AzureStorageRuntime method getAzureConnection.

public AzureConnection getAzureConnection(RuntimeContainer runtimeContainer) {
    TAzureStorageConnectionProperties conn = getUsedConnection(runtimeContainer);
    if (conn.useSharedAccessSignature.getValue()) {
        // extract account name and sas token from sas url
        Matcher m = Pattern.compile(SAS_PATTERN).matcher(conn.sharedAccessSignature.getValue());
        m.matches();
        return // 
        AzureConnectionWithSasService.builder().accountName(// 
        m.group(2)).sasToken(// 
        m.group(4)).build();
    } else {
        return // 
        AzureConnectionWithKeyService.builder().protocol(// 
        conn.protocol.getValue().toString().toLowerCase()).accountName(// 
        conn.accountName.getValue()).accountKey(conn.accountKey.getValue()).build();
    }
}
Also used : Matcher(java.util.regex.Matcher) TAzureStorageConnectionProperties(org.talend.components.azurestorage.tazurestorageconnection.TAzureStorageConnectionProperties)

Example 14 with TAzureStorageConnectionProperties

use of org.talend.components.azurestorage.tazurestorageconnection.TAzureStorageConnectionProperties in project components by Talend.

the class AzureStorageRuntime method initialize.

@Override
public ValidationResult initialize(RuntimeContainer runtimeContainer, ComponentProperties properties) {
    // init
    this.properties = (AzureStorageProvideConnectionProperties) properties;
    TAzureStorageConnectionProperties conn = getUsedConnection(runtimeContainer);
    // Validate connection properties
    String errorMessage = "";
    if (conn == null) {
        // check connection failure
        // $NON-NLS-1$
        errorMessage = messages.getMessage("error.VacantConnection");
    } else if (conn.useSharedAccessSignature.getValue()) {
        // checks
        if (StringUtils.isEmpty(conn.sharedAccessSignature.getStringValue())) {
            // $NON-NLS-1$
            errorMessage = messages.getMessage("error.EmptySAS");
        } else {
            Matcher m = Pattern.compile(SAS_PATTERN).matcher(conn.sharedAccessSignature.getValue());
            if (!m.matches()) {
                errorMessage = messages.getMessage("error.InvalidSAS");
            }
        }
    } else if (!conn.useSharedAccessSignature.getValue() && (StringUtils.isEmpty(conn.accountName.getStringValue()) || StringUtils.isEmpty(conn.accountKey.getStringValue()))) {
        // checks connection's account and key
        // $NON-NLS-1$
        errorMessage = messages.getMessage("error.EmptyKey");
    }
    // Return result
    if (errorMessage.isEmpty()) {
        return ValidationResult.OK;
    } else {
        return new ValidationResult(ValidationResult.Result.ERROR, errorMessage);
    }
}
Also used : Matcher(java.util.regex.Matcher) TAzureStorageConnectionProperties(org.talend.components.azurestorage.tazurestorageconnection.TAzureStorageConnectionProperties) ValidationResult(org.talend.daikon.properties.ValidationResult)

Example 15 with TAzureStorageConnectionProperties

use of org.talend.components.azurestorage.tazurestorageconnection.TAzureStorageConnectionProperties in project components by Talend.

the class AzureStorageRuntime method getUsedConnection.

public TAzureStorageConnectionProperties getUsedConnection(RuntimeContainer runtimeContainer) {
    TAzureStorageConnectionProperties connectionProperties = ((AzureStorageProvideConnectionProperties) properties).getConnectionProperties();
    String refComponentId = connectionProperties.getReferencedComponentId();
    // Using another component's connection
    if (refComponentId != null) {
        // In a runtime container
        if (runtimeContainer != null) {
            TAzureStorageConnectionProperties sharedConn = (TAzureStorageConnectionProperties) runtimeContainer.getComponentData(refComponentId, KEY_CONNECTION_PROPERTIES);
            if (sharedConn != null) {
                return sharedConn;
            }
        }
        // Design time
        connectionProperties = connectionProperties.getReferencedConnectionProperties();
    }
    if (runtimeContainer != null) {
        runtimeContainer.setComponentData(runtimeContainer.getCurrentComponentId(), KEY_CONNECTION_PROPERTIES, connectionProperties);
    }
    return connectionProperties;
}
Also used : AzureStorageProvideConnectionProperties(org.talend.components.azurestorage.AzureStorageProvideConnectionProperties) TAzureStorageConnectionProperties(org.talend.components.azurestorage.tazurestorageconnection.TAzureStorageConnectionProperties)

Aggregations

TAzureStorageConnectionProperties (org.talend.components.azurestorage.tazurestorageconnection.TAzureStorageConnectionProperties)27 RuntimeContainerMock (org.talend.components.azurestorage.RuntimeContainerMock)16 Before (org.junit.Before)14 Test (org.junit.Test)7 ValidationResult (org.talend.daikon.properties.ValidationResult)3 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 ComponentWizard (org.talend.components.api.wizard.ComponentWizard)2 TAzureStorageQueueCreateProperties (org.talend.components.azurestorage.queue.tazurestoragequeuecreate.TAzureStorageQueueCreateProperties)2 TAzureStorageOutputTableProperties (org.talend.components.azurestorage.table.tazurestorageoutputtable.TAzureStorageOutputTableProperties)2 NamedThing (org.talend.daikon.NamedThing)2 Form (org.talend.daikon.properties.presentation.Form)2 ComponentWizardDefinition (org.talend.components.api.wizard.ComponentWizardDefinition)1 WizardNameComparator (org.talend.components.api.wizard.WizardNameComparator)1 AzureStorageProvideConnectionProperties (org.talend.components.azurestorage.AzureStorageProvideConnectionProperties)1 AzureStorageSourceOrSink (org.talend.components.azurestorage.blob.runtime.AzureStorageSourceOrSink)1 TAzureStorageContainerCreateProperties (org.talend.components.azurestorage.blob.tazurestoragecontainercreate.TAzureStorageContainerCreateProperties)1 TAzureStorageContainerDeleteProperties (org.talend.components.azurestorage.blob.tazurestoragecontainerdelete.TAzureStorageContainerDeleteProperties)1 TAzureStorageContainerExistProperties (org.talend.components.azurestorage.blob.tazurestoragecontainerexist.TAzureStorageContainerExistProperties)1 TAzureStorageContainerListProperties (org.talend.components.azurestorage.blob.tazurestoragecontainerlist.TAzureStorageContainerListProperties)1