/** * 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); }
/** * 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); }
@Override public boolean checkComplete(final DistributionSet distributionSet) { return distributionSet.getModules().stream().map(SoftwareModule::getType).collect(Collectors.toList()) .containsAll(getMandatoryModuleTypes()); }
/** * Searches through modules for the given type. * * @param type * to search for * @return SoftwareModule of given type */ default Optional<SoftwareModule> findFirstModuleByType(final SoftwareModuleType type) { return getModules().stream().filter(module -> module.getType().equals(type)).findAny(); }
@Override public boolean checkComplete(final DistributionSet distributionSet) { return distributionSet.getModules().stream().map(SoftwareModule::getType).collect(Collectors.toList()) .containsAll(getMandatoryModuleTypes()); }
static List<DdiChunk> createChunks(final Target target, final Action uAction, final ArtifactUrlHandler artifactUrlHandler, final SystemManagement systemManagement, final HttpRequest request, final ControllerManagement controllerManagement) { final Map<Long, List<SoftwareModuleMetadata>> metadata = controllerManagement .findTargetVisibleMetaDataBySoftwareModuleId(uAction.getDistributionSet().getModules().stream() .map(SoftwareModule::getId).collect(Collectors.toList())); return uAction.getDistributionSet().getModules().stream() .map(module -> new DdiChunk(mapChunkLegacyKeys(module.getType().getKey()), module.getVersion(), module.getName(), createArtifacts(target, module, artifactUrlHandler, systemManagement, request), mapMetadata(metadata.get(module.getId())))) .collect(Collectors.toList()); }
static List<DdiChunk> createChunks(final Target target, final Action uAction, final ArtifactUrlHandler artifactUrlHandler, final SystemManagement systemManagement, final HttpRequest request, final ControllerManagement controllerManagement) { final Map<Long, List<SoftwareModuleMetadata>> metadata = controllerManagement .findTargetVisibleMetaDataBySoftwareModuleId(uAction.getDistributionSet().getModules().stream() .map(SoftwareModule::getId).collect(Collectors.toList())); return new ResponseList<>(uAction.getDistributionSet().getModules().stream() .map(module -> new DdiChunk(mapChunkLegacyKeys(module.getType().getKey()), module.getVersion(), module.getName(), createArtifacts(target, module, artifactUrlHandler, systemManagement, request), mapMetadata(metadata.get(module.getId())))) .collect(Collectors.toList())); }
private void lookIfUpdateAvailable(final Target target) { final Optional<Action> actionOptional = controllerManagement .findOldestActiveActionByTarget(target.getControllerId()); if (!actionOptional.isPresent()) { return; } final Action action = actionOptional.get(); if (action.isCancelingOrCanceled()) { amqpMessageDispatcherService.sendCancelMessageToTarget(target.getTenant(), target.getControllerId(), action.getId(), target.getAddress()); return; } final Map<SoftwareModule, List<SoftwareModuleMetadata>> modules = Maps .newHashMapWithExpectedSize(action.getDistributionSet().getModules().size()); final Map<Long, List<SoftwareModuleMetadata>> metadata = controllerManagement .findTargetVisibleMetaDataBySoftwareModuleId(action.getDistributionSet().getModules().stream() .map(SoftwareModule::getId).collect(Collectors.toList())); action.getDistributionSet().getModules().forEach(module -> modules.put(module, metadata.get(module.getId()))); amqpMessageDispatcherService.sendUpdateMessageToTarget(action.getTenant(), action.getTarget(), action.getId(), modules, action.isMaintenanceWindowAvailable()); }
/** * Method to send a message to a RabbitMQ Exchange after the Distribution * set has been assign to a Target. * * @param assignedEvent * the object to be send. */ @EventListener(classes = TargetAssignDistributionSetEvent.class) protected void targetAssignDistributionSet(final TargetAssignDistributionSetEvent assignedEvent) { if (isNotFromSelf(assignedEvent)) { return; } LOG.debug("targetAssignDistributionSet retrieved. I will forward it to DMF broker."); distributionSetManagement.get(assignedEvent.getDistributionSetId()).ifPresent(set -> { final Map<SoftwareModule, List<SoftwareModuleMetadata>> modules = Maps .newHashMapWithExpectedSize(set.getModules().size()); set.getModules() .forEach( module -> modules.put(module, softwareModuleManagement.findMetaDataBySoftwareModuleIdAndTargetVisible( PageRequest.of(0, RepositoryConstants.MAX_META_DATA_COUNT), module.getId()) .getContent())); targetManagement.getByControllerID(assignedEvent.getActions().keySet()) .forEach(target -> sendUpdateMessageToTarget(assignedEvent.getTenant(), target, assignedEvent.getActions().get(target.getControllerId()), modules, assignedEvent.isMaintenanceWindowAvailable())); }); }
public static String distributionSetUpdateValidFieldsOnly(final DistributionSet set) throws JSONException { 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("version", set.getVersion()).put("requiredMigrationStep", set.isRequiredMigrationStep()) .toString(); }
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)); }
public static JSONObject distributionSet(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("id", Long.MAX_VALUE) .put("version", set.getVersion()).put("createdAt", "0").put("updatedAt", "0") .put("createdBy", "fghdfkjghdfkjh").put("updatedBy", "fghdfkjghdfkjh") .put("requiredMigrationStep", set.isRequiredMigrationStep()).put("modules", new JSONArray(modules)); }
/** * 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(); }
/** * 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 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))); }
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))); }
protected DistributionSet createDistributionSet() { DistributionSet distributionSet = testdataFactory.createDistributionSet(""); distributionSet = distributionSetManagement.update(entityFactory.distributionSet() .update(distributionSet.getId()).description("The descption of the distribution set.")); distributionSet.getModules().forEach(module -> { final byte[] random = RandomStringUtils.random(5).getBytes(); artifactManagement .create(new ArtifactUpload(new ByteArrayInputStream(random), module.getId(), "file1", false, 0)); softwareModuleManagement.update(entityFactory.softwareModule().update(module.getId()) .description("Description of the software module")); }); return distributionSet; }
private void setSwModuleProperties(final SoftwareModuleType swModType, final Boolean isMandatory, final DistributionSet distributionSet) { final Set<SoftwareModule> alreadyAssignedSwModules = distributionSet.getModules(); final Item saveTblitem = getContainerDataSource().addItem(swModType.getName()); final Label mandatoryLabel = createMandatoryLabel(isMandatory); final Label typeName = HawkbitCommonUtil.getFormatedLabel(swModType.getName()); final VerticalLayout verticalLayout = createSoftModuleLayout(swModType, distributionSet, alreadyAssignedSwModules); saveTblitem.getItemProperty(SOFT_TYPE_MANDATORY).setValue(mandatoryLabel); saveTblitem.getItemProperty(SOFT_TYPE_NAME).setValue(typeName); saveTblitem.getItemProperty(SOFT_MODULE).setValue(verticalLayout); }
private void setSwModuleProperties(final SoftwareModuleType swModType, final Boolean isMandatory, final DistributionSet distributionSet) { final Set<SoftwareModule> alreadyAssignedSwModules = distributionSet.getModules(); final Item saveTblitem = getContainerDataSource().addItem(swModType.getName()); final Label mandatoryLabel = createMandatoryLabel(isMandatory); final Label typeName = HawkbitCommonUtil.getFormatedLabel(swModType.getName()); final VerticalLayout verticalLayout = createSoftModuleLayout(swModType, distributionSet, alreadyAssignedSwModules); saveTblitem.getItemProperty(SOFT_TYPE_MANDATORY).setValue(mandatoryLabel); saveTblitem.getItemProperty(SOFT_TYPE_NAME).setValue(typeName); saveTblitem.getItemProperty(SOFT_MODULE).setValue(verticalLayout); }
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; }