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();
}
};
}
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) };
}
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;
}
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());
}
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;
}
Aggregations