Search in sources :

Example 1 with AmazonConnectionInformationPortObject

use of org.knime.cloud.aws.util.AmazonConnectionInformationPortObject in project knime-cloud by knime.

the class BaseComprehendNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    if (inObjects == null || inObjects.length != 2) {
        throw new InvalidSettingsException("Invalid input data. Expected two inputs.");
    }
    final CloudConnectionInformation cxnInfo = ((AmazonConnectionInformationPortObject) inObjects[CNX_PORT_IDX]).getConnectionInformation();
    LOGGER.info("Using region: " + cxnInfo.getHost());
    // Create computation object for this operation.
    final BufferedDataTable table = (BufferedDataTable) inObjects[DATA_PORT_IDX];
    final DataTableSpec inputTableSpec = table.getDataTableSpec();
    final ComprehendOperation op = getOperationInstance(cxnInfo, generateOutputTableSpec(inputTableSpec), m_textColumnName.getStringValue());
    // Run the operation over the entire input.
    return new BufferedDataTable[] { op.compute(exec, table) };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) AmazonConnectionInformationPortObject(org.knime.cloud.aws.util.AmazonConnectionInformationPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) CloudConnectionInformation(org.knime.cloud.core.util.port.CloudConnectionInformation)

Example 2 with AmazonConnectionInformationPortObject

use of org.knime.cloud.aws.util.AmazonConnectionInformationPortObject in project knime-cloud by knime.

the class AmazonPersonalizeCreateCampaignNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    final CloudConnectionInformation cxnInfo = ((AmazonConnectionInformationPortObject) inObjects[0]).getConnectionInformation();
    try (final AmazonPersonalizeConnection personalizeConnection = new AmazonPersonalizeConnection(cxnInfo)) {
        final AmazonPersonalize personalizeClient = personalizeConnection.getClient();
        final CreateCampaignRequest createCampaignRequest = new CreateCampaignRequest();
        final CreateCampaignResult campaign = personalizeClient.createCampaign(createCampaignRequest.withName(m_settings.getCampaignName()).withSolutionVersionArn(m_settings.getSolutionVersion().getARN()).withMinProvisionedTPS(m_settings.getMinProvisionedTPS()));
        // TODO Test update of existing campaign
        try {
            final DescribeCampaignRequest describeCampaignRequest = new DescribeCampaignRequest().withCampaignArn(campaign.getCampaignArn());
            AmazonPersonalizeUtils.waitUntilActive(() -> {
                final DescribeCampaignResult campaignDescription = personalizeClient.describeCampaign(describeCampaignRequest);
                final String status = campaignDescription.getCampaign().getStatus();
                exec.setMessage("Creating campaign (Status: " + status + ")");
                if (status.equals(Status.CREATED_FAILED.getStatus())) {
                    personalizeClient.deleteCampaign(new DeleteCampaignRequest().withCampaignArn(campaignDescription.getCampaign().getCampaignArn()));
                    throw new IllegalStateException("No campaign has been created. Reason: " + campaignDescription.getCampaign().getFailureReason());
                }
                return status.equals(Status.ACTIVE.getStatus());
            }, 1000);
        } catch (InterruptedException e) {
            // TODO
            throw e;
        }
        if (m_settings.isOutputCampaignArnAsVar()) {
            pushFlowVariableString("campaign-ARN", campaign.getCampaignArn());
        }
    }
    return null;
}
Also used : AmazonPersonalizeConnection(org.knime.cloud.aws.mlservices.nodes.personalize.AmazonPersonalizeConnection) DescribeCampaignRequest(com.amazonaws.services.personalize.model.DescribeCampaignRequest) DeleteCampaignRequest(com.amazonaws.services.personalize.model.DeleteCampaignRequest) AmazonConnectionInformationPortObject(org.knime.cloud.aws.util.AmazonConnectionInformationPortObject) CreateCampaignResult(com.amazonaws.services.personalize.model.CreateCampaignResult) DescribeCampaignResult(com.amazonaws.services.personalize.model.DescribeCampaignResult) AmazonPersonalize(com.amazonaws.services.personalize.AmazonPersonalize) CloudConnectionInformation(org.knime.cloud.core.util.port.CloudConnectionInformation) CreateCampaignRequest(com.amazonaws.services.personalize.model.CreateCampaignRequest)

Example 3 with AmazonConnectionInformationPortObject

use of org.knime.cloud.aws.util.AmazonConnectionInformationPortObject in project knime-cloud by knime.

the class AmazonPersonalizeCreateSolutionVersionNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    final CloudConnectionInformation cxnInfo = ((AmazonConnectionInformationPortObject) inObjects[0]).getConnectionInformation();
    try (final AmazonPersonalizeConnection personalizeConnection = new AmazonPersonalizeConnection(cxnInfo)) {
        final AmazonPersonalize personalizeClient = personalizeConnection.getClient();
        // Create solution configuration or use existing one
        final String solutionArn;
        if (m_settings.isCreateNewSolution()) {
            solutionArn = createSolution(personalizeClient);
        } else {
            solutionArn = m_settings.getExistingSolution().getARN();
        }
        // Wait until the solution is active
        final DescribeSolutionRequest describeSolutionRequest = new DescribeSolutionRequest().withSolutionArn(solutionArn);
        AmazonPersonalizeUtils.waitUntilActive(() -> {
            DescribeSolutionResult describeSolution = personalizeClient.describeSolution(describeSolutionRequest);
            final String status = describeSolution.getSolution().getStatus();
            exec.setMessage("Creating solution configuration (Status: " + status + ")");
            return status.equals(Status.ACTIVE.getStatus());
        }, 100);
        exec.setProgress(0.5);
        // Create solution version
        final String solutionVersionArn = personalizeClient.createSolutionVersion(new CreateSolutionVersionRequest().withSolutionArn(solutionArn)).getSolutionVersionArn();
        // Wait until solution version is active (or failed)
        final DescribeSolutionVersionRequest describeSolutionVersionRequest = new DescribeSolutionVersionRequest().withSolutionVersionArn(solutionVersionArn);
        AmazonPersonalizeUtils.waitUntilActive(() -> {
            final DescribeSolutionVersionResult solutionVersionDescription = personalizeClient.describeSolutionVersion(describeSolutionVersionRequest);
            final String status = solutionVersionDescription.getSolutionVersion().getStatus();
            exec.setMessage("Creating solution version (Status: " + status + ")");
            if (status.equals(Status.CREATED_FAILED.getStatus())) {
                throw new IllegalStateException("No solution version has been created. Reason: " + solutionVersionDescription.getSolutionVersion().getFailureReason());
            }
            return status.equals(Status.ACTIVE.getStatus());
        }, 2000);
        // Retrieve the recipe type to put it into the output
        final DescribeSolutionVersionResult solutionVersionDescription = personalizeClient.describeSolutionVersion(describeSolutionVersionRequest);
        final String recipeType = personalizeClient.describeRecipe(new DescribeRecipeRequest().withRecipeArn(solutionVersionDescription.getSolutionVersion().getRecipeArn())).getRecipe().getRecipeType();
        // final String recipeType = personalizeClient.describeRecipe(new DescribeRecipeRequest().withRecipeArn(
        // personalizeClient.describeSolution(new DescribeSolutionRequest().withSolutionArn(solutionArn))
        // .getSolution().getRecipeArn()))
        // .getRecipe().getRecipeType();
        // Create output
        final Map<String, Double> metrics = personalizeClient.getSolutionMetrics(new GetSolutionMetricsRequest().withSolutionVersionArn(solutionVersionArn)).getMetrics();
        if (m_settings.isOutputSolutionVersionArnAsVar()) {
            pushFlowVariableString("solution-version-ARN", solutionVersionArn);
        }
        return new PortObject[] { createOutput(exec, solutionVersionArn, recipeType, metrics) };
    }
}
Also used : AmazonPersonalizeConnection(org.knime.cloud.aws.mlservices.nodes.personalize.AmazonPersonalizeConnection) DescribeRecipeRequest(com.amazonaws.services.personalize.model.DescribeRecipeRequest) GetSolutionMetricsRequest(com.amazonaws.services.personalize.model.GetSolutionMetricsRequest) DescribeSolutionResult(com.amazonaws.services.personalize.model.DescribeSolutionResult) AmazonPersonalize(com.amazonaws.services.personalize.AmazonPersonalize) DescribeSolutionVersionResult(com.amazonaws.services.personalize.model.DescribeSolutionVersionResult) CreateSolutionVersionRequest(com.amazonaws.services.personalize.model.CreateSolutionVersionRequest) DescribeSolutionRequest(com.amazonaws.services.personalize.model.DescribeSolutionRequest) AmazonConnectionInformationPortObject(org.knime.cloud.aws.util.AmazonConnectionInformationPortObject) DescribeSolutionVersionRequest(com.amazonaws.services.personalize.model.DescribeSolutionVersionRequest) CloudConnectionInformation(org.knime.cloud.core.util.port.CloudConnectionInformation) AmazonConnectionInformationPortObject(org.knime.cloud.aws.util.AmazonConnectionInformationPortObject) PortObject(org.knime.core.node.port.PortObject)

Example 4 with AmazonConnectionInformationPortObject

use of org.knime.cloud.aws.util.AmazonConnectionInformationPortObject in project knime-cloud by knime.

the class TranslateNodeModel method execute.

@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    if (inObjects == null || inObjects.length != 2) {
        throw new InvalidSettingsException("Invalid input data. Expected two inputs.");
    }
    final CloudConnectionInformation cxnInfo = ((AmazonConnectionInformationPortObject) inObjects[CNX_PORT_IDX]).getConnectionInformation();
    LOGGER.info("Using region: " + cxnInfo.getHost());
    // Access the input data table
    final BufferedDataTable table = (BufferedDataTable) inObjects[DATA_PORT_IDX];
    // Create computation object for the entity operation.
    final TranslateOperation translateOp = new TranslateOperation(cxnInfo, m_textColumnName.getStringValue(), TranslateUtils.getSourceLanguageMap().getOrDefault(m_sourceLanguage.getStringValue(), "auto"), TranslateUtils.getSourceLanguageMap().getOrDefault(m_targetLanguage.getStringValue(), "en"), createNewDataTableSpec(table.getDataTableSpec()));
    // Run the operation over the entire input.
    return new BufferedDataTable[] { translateOp.compute(exec, table) };
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) AmazonConnectionInformationPortObject(org.knime.cloud.aws.util.AmazonConnectionInformationPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) CloudConnectionInformation(org.knime.cloud.core.util.port.CloudConnectionInformation)

Example 5 with AmazonConnectionInformationPortObject

use of org.knime.cloud.aws.util.AmazonConnectionInformationPortObject in project knime-cloud by knime.

the class S3ConnectorNodeModel method execute.

@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    m_awsConnectionInfo = (AmazonConnectionInformationPortObject) inObjects[0];
    final CloudConnectionInformation conInfo = m_awsConnectionInfo.getConnectionInformation();
    final S3FSConnectionConfig config = m_settings.toFSConnectionConfig(conInfo, getCredentialsProvider());
    m_fsConn = new S3FSConnection(config);
    FSConnectionRegistry.getInstance().register(m_fsId, m_fsConn);
    if (conInfo.isUseAnonymous()) {
        setWarningMessage("You are using anonymous credentials. File browsing will only work inside public buckets.");
    } else {
        testFileSystemConnection(m_fsConn);
    }
    return new PortObject[] { new FileSystemPortObject(createSpec()) };
}
Also used : S3FSConnectionConfig(org.knime.cloud.aws.filehandling.s3.fs.api.S3FSConnectionConfig) S3FSConnection(org.knime.cloud.aws.filehandling.s3.fs.S3FSConnection) CloudConnectionInformation(org.knime.cloud.core.util.port.CloudConnectionInformation) FileSystemPortObject(org.knime.filehandling.core.port.FileSystemPortObject) AmazonConnectionInformationPortObject(org.knime.cloud.aws.util.AmazonConnectionInformationPortObject) FileSystemPortObject(org.knime.filehandling.core.port.FileSystemPortObject) PortObject(org.knime.core.node.port.PortObject)

Aggregations

AmazonConnectionInformationPortObject (org.knime.cloud.aws.util.AmazonConnectionInformationPortObject)6 CloudConnectionInformation (org.knime.cloud.core.util.port.CloudConnectionInformation)6 AmazonPersonalize (com.amazonaws.services.personalize.AmazonPersonalize)3 AmazonPersonalizeConnection (org.knime.cloud.aws.mlservices.nodes.personalize.AmazonPersonalizeConnection)3 BufferedDataTable (org.knime.core.node.BufferedDataTable)3 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 PortObject (org.knime.core.node.port.PortObject)2 CreateCampaignRequest (com.amazonaws.services.personalize.model.CreateCampaignRequest)1 CreateCampaignResult (com.amazonaws.services.personalize.model.CreateCampaignResult)1 CreateDatasetRequest (com.amazonaws.services.personalize.model.CreateDatasetRequest)1 CreateSolutionVersionRequest (com.amazonaws.services.personalize.model.CreateSolutionVersionRequest)1 DeleteCampaignRequest (com.amazonaws.services.personalize.model.DeleteCampaignRequest)1 DescribeCampaignRequest (com.amazonaws.services.personalize.model.DescribeCampaignRequest)1 DescribeCampaignResult (com.amazonaws.services.personalize.model.DescribeCampaignResult)1 DescribeRecipeRequest (com.amazonaws.services.personalize.model.DescribeRecipeRequest)1 DescribeSolutionRequest (com.amazonaws.services.personalize.model.DescribeSolutionRequest)1 DescribeSolutionResult (com.amazonaws.services.personalize.model.DescribeSolutionResult)1 DescribeSolutionVersionRequest (com.amazonaws.services.personalize.model.DescribeSolutionVersionRequest)1 DescribeSolutionVersionResult (com.amazonaws.services.personalize.model.DescribeSolutionVersionResult)1 GetSolutionMetricsRequest (com.amazonaws.services.personalize.model.GetSolutionMetricsRequest)1