Search in sources :

Example 1 with CloudConnectionInformation

use of org.knime.cloud.core.util.port.CloudConnectionInformation in project knime-cloud by knime.

the class BaseComprehendNodeModel method createStreamableOperator.

@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    final DataTableSpec spec = (DataTableSpec) inSpecs[DATA_PORT_IDX];
    final ConnectionInformationPortObjectSpec cnxSpec = (ConnectionInformationPortObjectSpec) inSpecs[CNX_PORT_IDX];
    final int textColIdx = spec.findColumnIndex(m_textColumnName.getStringValue());
    final CloudConnectionInformation cxnInfo = (CloudConnectionInformation) cnxSpec.getConnectionInformation();
    final ComprehendOperation op = getOperationInstance(cxnInfo, generateOutputTableSpec(((DataTableSpec) inSpecs[DATA_PORT_IDX])), m_textColumnName.getStringValue());
    return new StreamableOperator() {

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            final RowInput input = (RowInput) inputs[DATA_PORT_IDX];
            final RowOutput output = (RowOutput) outputs[0];
            final ComprehendConnection connection = new ComprehendConnection(cxnInfo);
            final AmazonComprehend comprehendClient = connection.getClient();
            op.compute(input, output, comprehendClient, textColIdx, exec, 0L);
            input.close();
            output.close();
        }
    };
}
Also used : ConnectionInformationPortObjectSpec(org.knime.base.filehandling.remote.connectioninformation.port.ConnectionInformationPortObjectSpec) DataTableSpec(org.knime.core.data.DataTableSpec) RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) AmazonComprehend(com.amazonaws.services.comprehend.AmazonComprehend) CloudConnectionInformation(org.knime.cloud.core.util.port.CloudConnectionInformation) RowInput(org.knime.core.node.streamable.RowInput)

Example 2 with CloudConnectionInformation

use of org.knime.cloud.core.util.port.CloudConnectionInformation 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 3 with CloudConnectionInformation

use of org.knime.cloud.core.util.port.CloudConnectionInformation in project knime-cloud by knime.

the class S3GenericConnectorNodeSettings method toFSConnectionConfig.

/**
 * Create {@link S3FSConnectionConfig} instance from this settings model.
 *
 * @param credentials
 * @return The FSConnectionConfig for S3
 * @throws IOException
 * @throws InvalidSettingsException
 */
public S3FSConnectionConfig toFSConnectionConfig(final CredentialsProvider credentials) throws IOException, InvalidSettingsException {
    final CloudConnectionInformation connInfo = toCloudConnInfo(credentials);
    final S3FSConnectionConfig config = super.toFSConnectionConfig(connInfo, credentials);
    config.setOverrideEndpoint(true);
    config.setEndpointUrl(getEndpointURL());
    config.setPathStyle(usePathStyle());
    return config;
}
Also used : S3FSConnectionConfig(org.knime.cloud.aws.filehandling.s3.fs.api.S3FSConnectionConfig) CloudConnectionInformation(org.knime.cloud.core.util.port.CloudConnectionInformation)

Example 4 with CloudConnectionInformation

use of org.knime.cloud.core.util.port.CloudConnectionInformation in project knime-cloud by knime.

the class AmazonPersonalizeCreateCampaignNodeDialog method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    // Check if a port object is available
    if (specs[0] == null) {
        throw new NotConfigurableException("No connection information available");
    }
    final CloudConnectionInformation connectionInformation = (CloudConnectionInformation) ((ConnectionInformationPortObjectSpec) specs[0]).getConnectionInformation();
    // Check if the port object has connection information
    if (connectionInformation == null) {
        throw new NotConfigurableException("No connection information available");
    }
    // Fill combo box with available solution versions
    try (final AmazonPersonalizeConnection personalizeConnection = new AmazonPersonalizeConnection(connectionInformation)) {
        final AmazonPersonalize personalize = personalizeConnection.getClient();
        final DefaultComboBoxModel<NameArnPair> comboBoxModel = new DefaultComboBoxModel<NameArnPair>(AmazonPersonalizeUtils.listAllSolutionVersions(personalize).stream().map(e -> new NameArnPair(shortARN(e.getSolutionVersionArn()), e.getSolutionVersionArn())).toArray(NameArnPair[]::new));
        if (comboBoxModel.getSize() == 0) {
            throw new InvalidSettingsException("No solution version available. You can create one using the 'Amazon Personalize Create Solution " + "Version' node.");
        }
        m_comboBoxSolutionVersionList.setModel(comboBoxModel);
        // Save the campaign names to check later if the specified name already exists
        m_campaignNames = AmazonPersonalizeUtils.listAllCampaigns(personalize).stream().map(e -> e.getName()).toArray(String[]::new);
    } catch (Exception e) {
        throw new NotConfigurableException(e.getMessage());
    }
    // Loading
    final AmazonPersonalizeCreateCampaignNodeSettings nodeSettings = new AmazonPersonalizeCreateCampaignNodeSettings();
    nodeSettings.loadSettingsForDialog(settings);
    m_textFieldCampaignName.setText(nodeSettings.getCampaignName());
    final NameArnPair solutionVersionARN = nodeSettings.getSolutionVersion();
    if (solutionVersionARN == null) {
        m_comboBoxSolutionVersionList.setSelectedItem(m_comboBoxSolutionVersionList.getItemAt(0));
    } else {
        m_comboBoxSolutionVersionList.setSelectedItem(solutionVersionARN);
    }
    m_spinnerMinNumProvisionedTransactions.setValue(nodeSettings.getMinProvisionedTPS());
    m_checkBoxOutputAsVariable.setSelected(nodeSettings.isOutputCampaignArnAsVar());
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) AmazonPersonalizeConnection(org.knime.cloud.aws.mlservices.nodes.personalize.AmazonPersonalizeConnection) NameArnPair(org.knime.cloud.aws.mlservices.utils.personalize.NameArnPair) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) AmazonPersonalize(com.amazonaws.services.personalize.AmazonPersonalize) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) CloudConnectionInformation(org.knime.cloud.core.util.port.CloudConnectionInformation) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NotConfigurableException(org.knime.core.node.NotConfigurableException)

Example 5 with CloudConnectionInformation

use of org.knime.cloud.core.util.port.CloudConnectionInformation 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)

Aggregations

CloudConnectionInformation (org.knime.cloud.core.util.port.CloudConnectionInformation)18 AmazonPersonalize (com.amazonaws.services.personalize.AmazonPersonalize)6 AmazonPersonalizeConnection (org.knime.cloud.aws.mlservices.nodes.personalize.AmazonPersonalizeConnection)6 AmazonConnectionInformationPortObject (org.knime.cloud.aws.util.AmazonConnectionInformationPortObject)6 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)6 URI (java.net.URI)4 DataTableSpec (org.knime.core.data.DataTableSpec)4 DescribeRecipeRequest (com.amazonaws.services.personalize.model.DescribeRecipeRequest)3 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)3 ConnectionInformationPortObjectSpec (org.knime.base.filehandling.remote.connectioninformation.port.ConnectionInformationPortObjectSpec)3 S3FSConnectionConfig (org.knime.cloud.aws.filehandling.s3.fs.api.S3FSConnectionConfig)3 NameArnPair (org.knime.cloud.aws.mlservices.utils.personalize.NameArnPair)3 BufferedDataTable (org.knime.core.node.BufferedDataTable)3 NotConfigurableException (org.knime.core.node.NotConfigurableException)3 DescribeCampaignRequest (com.amazonaws.services.personalize.model.DescribeCampaignRequest)2 DescribeSolutionVersionRequest (com.amazonaws.services.personalize.model.DescribeSolutionVersionRequest)2 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)2 RecipeType (org.knime.cloud.aws.mlservices.utils.personalize.RecipeType)2 CloudConnectionInformationPortObjectSpec (org.knime.cloud.core.util.port.CloudConnectionInformationPortObjectSpec)2 ExecutionContext (org.knime.core.node.ExecutionContext)2