public static JSONObject distributionSetCreateValidFieldsOnly(final DistributionSet set) throws JSONException { final List<JSONObject> modules = set.getModules().stream().map(module -> { try { return new JSONObject().put("id", module.getId()); } catch (final JSONException e) { e.printStackTrace(); return null; } }).collect(Collectors.toList()); return new JSONObject().put("name", set.getName()).put("description", set.getDescription()) .put("type", set.getType() == null ? null : set.getType().getKey()).put("version", set.getVersion()) .put("requiredMigrationStep", set.isRequiredMigrationStep()).put("modules", new JSONArray(modules)); }
private List<ProxyDistribution> createProxyDistributions(final Page<DistributionSet> distBeans) { final List<ProxyDistribution> proxyDistributions = new ArrayList<>(); for (final DistributionSet distributionSet : distBeans) { final ProxyDistribution proxyDistribution = new ProxyDistribution(); proxyDistribution.setName( HawkbitCommonUtil.getFormattedNameVersion(distributionSet.getName(), distributionSet.getVersion())); proxyDistribution.setDescription(distributionSet.getDescription()); proxyDistribution.setDistId(distributionSet.getId()); proxyDistribution.setId(distributionSet.getId()); proxyDistribution.setVersion(distributionSet.getVersion()); proxyDistribution.setCreatedDate(SPDateTimeUtil.getFormattedDate(distributionSet.getCreatedAt())); proxyDistribution.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(distributionSet.getLastModifiedAt())); proxyDistribution.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(distributionSet)); proxyDistribution.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(distributionSet)); proxyDistribution.setIsComplete(distributionSet.isComplete()); proxyDistributions.add(proxyDistribution); } return proxyDistributions; }
protected Long getOsModule(final DistributionSet ds) { return ds.findFirstModuleByType(osType).get().getId(); }
/** * Constructor. * * @param distributionSet * the distributionSet */ public DistributionSetIdName(final DistributionSet distributionSet) { this(distributionSet.getId(), distributionSet.getName(), distributionSet.getVersion()); }
@Override void sendAssignmentEvents(final DistributionSet set, final List<JpaTarget> targets, final Set<Long> targetIdsCancellList, final Map<String, JpaAction> targetIdsToActions) { final List<Action> actions = targets.stream().map(target -> { target.setUpdateStatus(TargetUpdateStatus.PENDING); sendTargetUpdatedEvent(target); return target; }).filter(target -> !targetIdsCancellList.contains(target.getId())).map(Target::getControllerId) .map(targetIdsToActions::get).collect(Collectors.toList()); sendTargetAssignDistributionSetEvent(set.getTenant(), set.getId(), actions); }
private void populateValuesOfDistribution(final Long editDistId) { final Optional<DistributionSet> distSet = distributionSetManagement.getWithDetails(editDistId); if (!distSet.isPresent()) { return; } distNameTextField.setValue(distSet.get().getName()); distVersionTextField.setValue(distSet.get().getVersion()); if (distSet.get().getType().isDeleted()) { distsetTypeNameComboBox.addItem(distSet.get().getType().getId()); } distsetTypeNameComboBox.setValue(distSet.get().getType().getId()); distsetTypeNameComboBox.setEnabled(false); reqMigStepCheckbox.setValue(distSet.get().isRequiredMigrationStep()); descTextArea.setValue(distSet.get().getDescription()); }
static MgmtDistributionSet toResponse(final DistributionSet distributionSet) { if (distributionSet == null) { return null; } final MgmtDistributionSet response = new MgmtDistributionSet(); MgmtRestModelMapper.mapNamedToNamed(response, distributionSet); response.setDsId(distributionSet.getId()); response.setVersion(distributionSet.getVersion()); response.setComplete(distributionSet.isComplete()); response.setType(distributionSet.getType().getKey()); response.setDeleted(distributionSet.isDeleted()); distributionSet.getModules() .forEach(module -> response.getModules().add(MgmtSoftwareModuleMapper.toResponse(module))); response.setRequiredMigrationStep(distributionSet.isRequiredMigrationStep()); response.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getDistributionSet(response.getDsId())) .withSelfRel()); return response; }
/** * Creates {@link DistributionSet}s in repository including three * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT} * , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} followed by an * iterative number and {@link DistributionSet#isRequiredMigrationStep()} * <code>false</code>. * * In addition it updates the created {@link DistributionSet}s and * {@link SoftwareModule}s to ensure that * {@link BaseEntity#getLastModifiedAt()} and * {@link BaseEntity#getLastModifiedBy()} is filled. * * @return persisted {@link DistributionSet}. */ public DistributionSet createUpdatedDistributionSet() { DistributionSet set = createDistributionSet(""); set = distributionSetManagement.update( entityFactory.distributionSet().update(set.getId()).description("Updated " + DEFAULT_DESCRIPTION)); set.getModules().forEach(module -> softwareModuleManagement.update( entityFactory.softwareModule().update(module.getId()).description("Updated " + DEFAULT_DESCRIPTION))); // load also lazy stuff return distributionSetManagement.getWithDetails(set.getId()).get(); }
private boolean validateAssignment(final SoftwareModule sm, final DistributionSet ds) { final String dsNameAndVersion = HawkbitCommonUtil.concatStrings(":", ds.getName(), ds.getVersion()); final String smNameAndVersion = HawkbitCommonUtil.concatStrings(":", sm.getName(), sm.getVersion()); if (!isSoftwareModuleDragged(ds.getId(), sm)) { return false; return false; if (targetManagement.countByFilters(null, null, null, ds.getId(), Boolean.FALSE, new String[] {}) > 0) { return false; if (ds.getModules().contains(sm)) { return false; if (!ds.getType().containsModuleType(sm.getType())) { return false; if (distributionSetManagement.isInUse(ds.getId())) { getNotification() .displayValidationError(getI18n().getMessage("message.error.notification.ds.target.assigned", ds.getName(), ds.getVersion())); return false;
protected DistributionSetAssignmentResult assignDistributionSet(final DistributionSet pset, final List<Target> targets) { return deploymentManagement.assignDistributionSet(pset.getId(), targets.stream().map(Target::getTargetWithActionType).collect(Collectors.toList())); }
/** * Adds {@link SoftwareModuleMetadata} to every module of given * {@link DistributionSet}. * * {@link #VISIBLE_SM_MD_VALUE}, {@link #VISIBLE_SM_MD_KEY} with * {@link SoftwareModuleMetadata#isTargetVisible()} and * {@link #INVISIBLE_SM_MD_KEY}, {@link #INVISIBLE_SM_MD_VALUE} without * {@link SoftwareModuleMetadata#isTargetVisible()} * * @param set * to add metadata to */ public void addSoftwareModuleMetadata(final DistributionSet set) { set.getModules().forEach(this::addTestModuleMetadata); }
private void populateDistributionDtls(final VerticalLayout layout, final DistributionSet distributionSet) { layout.removeAllComponents(); layout.addComponent(SPUIComponentProvider.createNameValueLabel(getI18n().getMessage("label.dist.details.name"), distributionSet == null ? "" : distributionSet.getName())); layout.addComponent( SPUIComponentProvider.createNameValueLabel(getI18n().getMessage("label.dist.details.version"), distributionSet == null ? "" : distributionSet.getVersion())); if (distributionSet == null) { return; } distributionSet.getModules() .forEach(module -> layout.addComponent(getSWModlabel(module.getType().getName(), module))); }
final Set<SoftwareModule> swModules = distributionSet.getModules(); swModules.forEach(swModule -> { swModuleNames.append(swModule.getName()); stringBuilder.append(HTML_UL_OPEN_TAG); stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append(" DistributionSet Description : ").append(distributionSet.getDescription()); stringBuilder.append(HTML_LI_CLOSE_TAG); stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append(" DistributionSet Type : ").append((distributionSet.getType()).getName()); stringBuilder.append(HTML_LI_CLOSE_TAG); stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append(" Required Migration step : ") .append(distributionSet.isRequiredMigrationStep() ? "Yes" : "No"); stringBuilder.append(HTML_LI_CLOSE_TAG); stringBuilder.append(HTML_LI_OPEN_TAG);
@Override public void saveOrUpdate() { if (isDuplicate(editDistId)) { return; } final boolean isMigStepReq = reqMigStepCheckbox.getValue(); final Long distSetTypeId = (Long) distsetTypeNameComboBox.getValue(); distributionSetTypeManagement.get(distSetTypeId).ifPresent(type -> { final DistributionSet currentDS = distributionSetManagement.update(entityFactory.distributionSet() .update(editDistId).name(distNameTextField.getValue()).description(descTextArea.getValue()) .version(distVersionTextField.getValue()).requiredMigrationStep(isMigStepReq)); notificationMessage.displaySuccess(i18n.getMessage("message.new.dist.save.success", new Object[] { currentDS.getName(), currentDS.getVersion() })); // update table row+details layout eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.UPDATED_ENTITY, currentDS)); }); }
@Override @SuppressWarnings("unchecked") protected void updateEntity(final DistributionSet baseEntity, final Item item) { item.getItemProperty(SPUILabelDefinitions.DIST_ID).setValue(baseEntity.getId()); item.getItemProperty(SPUILabelDefinitions.VAR_IS_DISTRIBUTION_COMPLETE).setValue(baseEntity.isComplete()); super.updateEntity(baseEntity, item); }
protected void populateDetails() { if (getSelectedBaseEntity() != null) { updateDistributionSetDetailsLayout(getSelectedBaseEntity().getType().getName(), getSelectedBaseEntity().isRequiredMigrationStep()); } else { updateDistributionSetDetailsLayout(null, null); } }
static void addLinks(final DistributionSet distributionSet, final MgmtDistributionSet response) { response.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getAssignedSoftwareModules(response.getDsId(), MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE, MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null)) .withRel(MgmtRestConstants.DISTRIBUTIONSET_V1_MODULE)); response.add(linkTo(methodOn(MgmtDistributionSetTypeRestApi.class) .getDistributionSetType(distributionSet.getType().getId())).withRel("type")); response.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getMetadata(response.getDsId(), MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE, MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null)).withRel("metadata")); }
@Test @Description("Delete a software module assignment." + " Required Permission: " + SpPermission.UPDATE_REPOSITORY) public void deleteAssignSoftwareModules() throws Exception { final DistributionSet set = testdataFactory.createUpdatedDistributionSet(); mockMvc.perform(delete( MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{distributionSetId}/assignedSM/{softwareModuleId}", set.getId(), set.findFirstModuleByType(osType).get().getId()) .contentType(MediaType.APPLICATION_JSON_UTF8)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document(pathParameters( parameterWithName("distributionSetId").description(ApiModelPropertiesGeneric.ITEM_ID), parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID)))); ; }
/** * Populate software module table. * * @param distributionSet */ public void populateModule(final DistributionSet distributionSet) { removeAllItems(); if (distributionSet != null) { if (isUnassignSoftModAllowed && permissionChecker.hasUpdateRepositoryPermission()) { try { isTargetAssigned = false; } catch (final EntityReadOnlyException exception) { isTargetAssigned = true; LOG.info("Target already assigned for the distribution set: " + distributionSet.getName(), exception); } } final Set<SoftwareModuleType> swModuleMandatoryTypes = distributionSet.getType().getMandatoryModuleTypes(); final Set<SoftwareModuleType> swModuleOptionalTypes = distributionSet.getType().getOptionalModuleTypes(); if (!CollectionUtils.isEmpty(swModuleMandatoryTypes)) { swModuleMandatoryTypes.forEach(swModule -> setSwModuleProperties(swModule, true, distributionSet)); } if (!CollectionUtils.isEmpty(swModuleOptionalTypes)) { swModuleOptionalTypes.forEach(swModule -> setSwModuleProperties(swModule, false, distributionSet)); } setAmountOfTableRows(getContainerDataSource().size()); } }
/** * Creates {@link DistributionSet}s in repository including three * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT} * , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} followed by an * iterative number and {@link DistributionSet#isRequiredMigrationStep()} * <code>false</code>. * * In addition it updates the created {@link DistributionSet}s and * {@link SoftwareModule}s to ensure that * {@link BaseEntity#getLastModifiedAt()} and * {@link BaseEntity#getLastModifiedBy()} is filled. * * @return persisted {@link DistributionSet}. */ public DistributionSet createUpdatedDistributionSet() { DistributionSet set = createDistributionSet(""); set = distributionSetManagement.update( entityFactory.distributionSet().update(set.getId()).description("Updated " + DEFAULT_DESCRIPTION)); set.getModules().forEach(module -> softwareModuleManagement.update( entityFactory.softwareModule().update(module.getId()).description("Updated " + DEFAULT_DESCRIPTION))); // load also lazy stuff return distributionSetManagement.getWithDetails(set.getId()).get(); }