use of org.knime.cloud.aws.mlservices.nodes.personalize.AmazonPersonalizeConnection 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.aws.mlservices.nodes.personalize.AmazonPersonalizeConnection 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;
}
use of org.knime.cloud.aws.mlservices.nodes.personalize.AmazonPersonalizeConnection 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) };
}
}
use of org.knime.cloud.aws.mlservices.nodes.personalize.AmazonPersonalizeConnection 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();
}
use of org.knime.cloud.aws.mlservices.nodes.personalize.AmazonPersonalizeConnection 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);
}
Aggregations