Search in sources :

Example 1 with RecipeSummary

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

the class AmazonPersonalizeCreateSolutionVersionNodeDialog method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    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");
    }
    // List all existing dataset groups and solutions
    try (final AmazonPersonalizeConnection personalizeConnection = new AmazonPersonalizeConnection(connectionInformation)) {
        final AmazonPersonalize personalizeClient = personalizeConnection.getClient();
        final List<DatasetGroupSummary> listAllDatasetGroups = AmazonPersonalizeUtils.listAllDatasetGroups(personalizeClient);
        if (listAllDatasetGroups.size() == 0) {
            throw new NotConfigurableException("No existing dataset group found. Upload datasets first.");
        }
        final DefaultComboBoxModel<NameArnPair> comboBoxModel = new DefaultComboBoxModel<NameArnPair>(listAllDatasetGroups.stream().map(e -> NameArnPair.of(e.getName(), e.getDatasetGroupArn())).toArray(NameArnPair[]::new));
        m_comboBoxDatasetGroupList.setModel(comboBoxModel);
        final DefaultComboBoxModel<NameArnPair> comboBoxModel2 = new DefaultComboBoxModel<NameArnPair>(AmazonPersonalizeUtils.listAllSolutions(personalizeClient).stream().map(e -> NameArnPair.of(e.getName(), e.getSolutionArn())).toArray(NameArnPair[]::new));
        m_comboBoxExistingSolutions.setModel(comboBoxModel2);
        final DefaultComboBoxModel<NameArnPair> comboBoxModelUserPersonalization = new DefaultComboBoxModel<>();
        final DefaultComboBoxModel<NameArnPair> comboBoxModelPersonalizedRanking = new DefaultComboBoxModel<>();
        final DefaultComboBoxModel<NameArnPair> comboBoxModelRelatedItems = new DefaultComboBoxModel<>();
        for (RecipeSummary rs : AmazonPersonalizeUtils.listAllRecipes(personalizeClient)) {
            final Recipe recipe = personalizeClient.describeRecipe(new DescribeRecipeRequest().withRecipeArn(rs.getRecipeArn())).getRecipe();
            final NameArnPair nameArnPair = NameArnPair.of(recipe.getName(), recipe.getRecipeArn());
            switch(RecipeType.ofRecipeType(recipe)) {
                case USER_PERSONALIZATION:
                    comboBoxModelUserPersonalization.addElement(nameArnPair);
                    break;
                case PERSONALIZED_RANKING:
                    comboBoxModelPersonalizedRanking.addElement(nameArnPair);
                    break;
                case RELATED_ITEMS:
                    comboBoxModelRelatedItems.addElement(nameArnPair);
                    break;
            }
        }
        m_comboBoxUserPersonalizationRecipeList.setModel(comboBoxModelUserPersonalization);
        m_comboBoxPersonalizedRankingRecipeList.setModel(comboBoxModelPersonalizedRanking);
        m_comboBoxRelatedItemsRecipeList.setModel(comboBoxModelRelatedItems);
    } catch (Exception e) {
        throw new NotConfigurableException(e.getMessage());
    }
    // Loading
    final AmazonPersonalizeCreateSolutionVersionNodeSettings nodeSettings = new AmazonPersonalizeCreateSolutionVersionNodeSettings();
    nodeSettings.loadSettingsForDialog(settings);
    m_radioButtonCreateNewSolution.setSelected(nodeSettings.isCreateNewSolution());
    m_radioButtonUseExistingSolution.setSelected(!nodeSettings.isCreateNewSolution());
    final NameArnPair datasetGroup = nodeSettings.getDatasetGroup();
    if (datasetGroup == null) {
        m_comboBoxDatasetGroupList.setSelectedIndex(0);
    } else {
        m_comboBoxDatasetGroupList.setSelectedItem(datasetGroup);
    }
    final RecipeSelection recipeSelection = nodeSettings.getRecipeSelection();
    m_radioButtonPredefinedRecipe.setSelected(recipeSelection == RecipeSelection.PREDEFINED);
    m_radioButtonUserDefinedRecipe.setSelected(recipeSelection == RecipeSelection.USER_DEFINED);
    m_radioButtonAutoML.setSelected(recipeSelection == RecipeSelection.AUTOML);
    final RecipeType predefinedRecipeType = nodeSettings.getPredefinedRecipeType();
    final NameArnPair predefinedRecipe = nodeSettings.getPredefinedRecipe();
    if (predefinedRecipeType == RecipeType.USER_PERSONALIZATION) {
        m_radioButtonUserPersonalization.setSelected(true);
        if (predefinedRecipe != null) {
            m_comboBoxUserPersonalizationRecipeList.setSelectedItem(predefinedRecipe);
        }
    }
    if (predefinedRecipeType == RecipeType.PERSONALIZED_RANKING) {
        m_radioButtonPersonalizedRanking.setSelected(true);
        m_comboBoxPersonalizedRankingRecipeList.setSelectedItem(predefinedRecipe);
    }
    if (predefinedRecipeType == RecipeType.RELATED_ITEMS) {
        m_radioButtonRelatedItems.setSelected(true);
        m_comboBoxRelatedItemsRecipeList.setSelectedItem(predefinedRecipe);
    }
    m_textFieldUserDefinedRecipeArn.setText(nodeSettings.getUserDefinedRecipeArn());
    m_checkBoxHyperParamOpt.setSelected(nodeSettings.isHyperparameterOpt());
    m_textFieldPrefixSolutionName.setText(nodeSettings.getSolutionName());
    m_checkBoxOutputSolutionVersionARNAsVar.setSelected(nodeSettings.isOutputSolutionVersionArnAsVar());
    final NameArnPair existingSolution = nodeSettings.getExistingSolution();
    if (existingSolution == null && m_comboBoxExistingSolutions.getModel().getSize() > 0) {
        m_comboBoxExistingSolutions.setSelectedIndex(0);
    } else {
        m_comboBoxExistingSolutions.setSelectedItem(existingSolution);
    }
    enablePanelComponents(m_createNewSolutionPanel, !m_radioButtonUseExistingSolution.isSelected());
    enablePanelComponents(m_useExistingSolutionPanel, m_radioButtonUseExistingSolution.isSelected());
    enableComponents();
}
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) DescribeRecipeRequest(com.amazonaws.services.personalize.model.DescribeRecipeRequest) Recipe(com.amazonaws.services.personalize.model.Recipe) AmazonPersonalize(com.amazonaws.services.personalize.AmazonPersonalize) DatasetGroupSummary(com.amazonaws.services.personalize.model.DatasetGroupSummary) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NotConfigurableException(org.knime.core.node.NotConfigurableException) RecipeType(org.knime.cloud.aws.mlservices.utils.personalize.RecipeType) CloudConnectionInformation(org.knime.cloud.core.util.port.CloudConnectionInformation) RecipeSummary(com.amazonaws.services.personalize.model.RecipeSummary)

Example 2 with RecipeSummary

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

the class AmazonPersonalizeUtils method listAllRecipes.

/**
 * @param personalize the amazon personalize client
 * @return all recipes
 */
public static List<RecipeSummary> listAllRecipes(final AmazonPersonalize personalize) {
    final ListRecipesRequest request = new ListRecipesRequest().withMaxResults(100);
    ListRecipesResult result = personalize.listRecipes(request);
    List<RecipeSummary> list = result.getRecipes();
    String nextToken;
    while ((nextToken = result.getNextToken()) != null) {
        result = personalize.listRecipes(request.withNextToken(nextToken));
        list.addAll(result.getRecipes());
    }
    return list;
}
Also used : ListRecipesRequest(com.amazonaws.services.personalize.model.ListRecipesRequest) ListRecipesResult(com.amazonaws.services.personalize.model.ListRecipesResult) RecipeSummary(com.amazonaws.services.personalize.model.RecipeSummary)

Aggregations

RecipeSummary (com.amazonaws.services.personalize.model.RecipeSummary)2 AmazonPersonalize (com.amazonaws.services.personalize.AmazonPersonalize)1 DatasetGroupSummary (com.amazonaws.services.personalize.model.DatasetGroupSummary)1 DescribeRecipeRequest (com.amazonaws.services.personalize.model.DescribeRecipeRequest)1 ListRecipesRequest (com.amazonaws.services.personalize.model.ListRecipesRequest)1 ListRecipesResult (com.amazonaws.services.personalize.model.ListRecipesResult)1 Recipe (com.amazonaws.services.personalize.model.Recipe)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 AmazonPersonalizeConnection (org.knime.cloud.aws.mlservices.nodes.personalize.AmazonPersonalizeConnection)1 NameArnPair (org.knime.cloud.aws.mlservices.utils.personalize.NameArnPair)1 RecipeType (org.knime.cloud.aws.mlservices.utils.personalize.RecipeType)1 CloudConnectionInformation (org.knime.cloud.core.util.port.CloudConnectionInformation)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 NotConfigurableException (org.knime.core.node.NotConfigurableException)1