Search in sources :

Example 1 with DescribeCampaignRequest

use of com.amazonaws.services.personalize.model.DescribeCampaignRequest 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 2 with DescribeCampaignRequest

use of com.amazonaws.services.personalize.model.DescribeCampaignRequest in project knime-cloud by knime.

the class AbstractAmazonPersonalizePredictNodeDialog method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    final ConnectionInformationPortObjectSpec object = (ConnectionInformationPortObjectSpec) specs[0];
    final CloudConnectionInformation connectionInformation = (CloudConnectionInformation) object.getConnectionInformation();
    // Check if the port object has connection information
    if (connectionInformation == null) {
        throw new NotConfigurableException("No connection information available");
    }
    // List all existing campaigns
    try (final AmazonPersonalizeConnection personalizeConnection = new AmazonPersonalizeConnection(connectionInformation)) {
        final AmazonPersonalize personalizeClient = personalizeConnection.getClient();
        // Filter only the campaigns that have a solution with the proper recipe type
        final DefaultComboBoxModel<NameArnPair> comboBoxModel = new DefaultComboBoxModel<NameArnPair>(AmazonPersonalizeUtils.listAllCampaigns(personalizeClient).stream().filter(e -> {
            final String recipeType = personalizeClient.describeRecipe(new DescribeRecipeRequest().withRecipeArn(personalizeClient.describeSolutionVersion(new DescribeSolutionVersionRequest().withSolutionVersionArn(personalizeClient.describeCampaign(new DescribeCampaignRequest().withCampaignArn(e.getCampaignArn())).getCampaign().getSolutionVersionArn())).getSolutionVersion().getRecipeArn())).getRecipe().getRecipeType();
            return recipeType.equals(getRecipeType().getType());
        }).map(e -> new NameArnPair(e.getName(), e.getCampaignArn())).toArray(NameArnPair[]::new));
        m_comboBoxCampaigns.setModel(comboBoxModel);
        if (comboBoxModel.getSize() == 0) {
            throw new NotConfigurableException("No campaign of type '" + getRecipeType().toString() + "' found. You can create one using the 'Amazon Personalize Create Campaign' node.");
        }
    } catch (Exception e) {
        throw new NotConfigurableException(e.getMessage());
    }
    // Loading
    final DataTableSpec spec = (DataTableSpec) specs[1];
    m_settings.loadSettingsForDialog(settings);
    final NameArnPair campaign = m_settings.getCampaign();
    if (campaign != null) {
        m_comboBoxCampaigns.setSelectedItem(campaign);
    } else {
        m_comboBoxCampaigns.setSelectedItem(m_comboBoxCampaigns.getItemAt(0));
    }
    m_colSelectionUserID.update(spec, m_settings.getUserIDCol());
    m_colSelectionItemID.update(spec, m_settings.getItemIDCol());
    m_radioButtonFail.setSelected(m_settings.getMissingValueHandling() == MissingValueHandling.FAIL);
    m_radioButtonIgnore.setSelected(m_settings.getMissingValueHandling() == MissingValueHandling.IGNORE);
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ConnectionInformationPortObjectSpec(org.knime.base.filehandling.remote.connectioninformation.port.ConnectionInformationPortObjectSpec) NodeDialogPane(org.knime.core.node.NodeDialogPane) CloudConnectionInformation(org.knime.cloud.core.util.port.CloudConnectionInformation) NotConfigurableException(org.knime.core.node.NotConfigurableException) AmazonPersonalizeUtils(org.knime.cloud.aws.mlservices.utils.personalize.AmazonPersonalizeUtils) NodeUtils(org.knime.base.filehandling.NodeUtils) ColumnSelectionPanel(org.knime.core.node.util.ColumnSelectionPanel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) JComboBox(javax.swing.JComboBox) AmazonPersonalizeConnection(org.knime.cloud.aws.mlservices.nodes.personalize.AmazonPersonalizeConnection) DescribeRecipeRequest(com.amazonaws.services.personalize.model.DescribeRecipeRequest) StringValue(org.knime.core.data.StringValue) NameArnPair(org.knime.cloud.aws.mlservices.utils.personalize.NameArnPair) ButtonGroup(javax.swing.ButtonGroup) DescribeSolutionVersionRequest(com.amazonaws.services.personalize.model.DescribeSolutionVersionRequest) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) BorderFactory(javax.swing.BorderFactory) AmazonPersonalize(com.amazonaws.services.personalize.AmazonPersonalize) GridBagConstraints(java.awt.GridBagConstraints) JRadioButton(javax.swing.JRadioButton) RecipeType(org.knime.cloud.aws.mlservices.utils.personalize.RecipeType) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) DataValueColumnFilter(org.knime.core.node.util.DataValueColumnFilter) JLabel(javax.swing.JLabel) GridBagLayout(java.awt.GridBagLayout) DescribeCampaignRequest(com.amazonaws.services.personalize.model.DescribeCampaignRequest) JPanel(javax.swing.JPanel) WordUtils(org.apache.commons.lang.WordUtils) AmazonPersonalizeConnection(org.knime.cloud.aws.mlservices.nodes.personalize.AmazonPersonalizeConnection) NameArnPair(org.knime.cloud.aws.mlservices.utils.personalize.NameArnPair) DescribeCampaignRequest(com.amazonaws.services.personalize.model.DescribeCampaignRequest) DescribeRecipeRequest(com.amazonaws.services.personalize.model.DescribeRecipeRequest) DataTableSpec(org.knime.core.data.DataTableSpec) AmazonPersonalize(com.amazonaws.services.personalize.AmazonPersonalize) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NotConfigurableException(org.knime.core.node.NotConfigurableException) ConnectionInformationPortObjectSpec(org.knime.base.filehandling.remote.connectioninformation.port.ConnectionInformationPortObjectSpec) DescribeSolutionVersionRequest(com.amazonaws.services.personalize.model.DescribeSolutionVersionRequest) CloudConnectionInformation(org.knime.cloud.core.util.port.CloudConnectionInformation)

Aggregations

AmazonPersonalize (com.amazonaws.services.personalize.AmazonPersonalize)2 DescribeCampaignRequest (com.amazonaws.services.personalize.model.DescribeCampaignRequest)2 AmazonPersonalizeConnection (org.knime.cloud.aws.mlservices.nodes.personalize.AmazonPersonalizeConnection)2 CloudConnectionInformation (org.knime.cloud.core.util.port.CloudConnectionInformation)2 CreateCampaignRequest (com.amazonaws.services.personalize.model.CreateCampaignRequest)1 CreateCampaignResult (com.amazonaws.services.personalize.model.CreateCampaignResult)1 DeleteCampaignRequest (com.amazonaws.services.personalize.model.DeleteCampaignRequest)1 DescribeCampaignResult (com.amazonaws.services.personalize.model.DescribeCampaignResult)1 DescribeRecipeRequest (com.amazonaws.services.personalize.model.DescribeRecipeRequest)1 DescribeSolutionVersionRequest (com.amazonaws.services.personalize.model.DescribeSolutionVersionRequest)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 BorderFactory (javax.swing.BorderFactory)1 ButtonGroup (javax.swing.ButtonGroup)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 JComboBox (javax.swing.JComboBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JRadioButton (javax.swing.JRadioButton)1 WordUtils (org.apache.commons.lang.WordUtils)1