/** * Creates {@link Target}s in repository and with * {@link #DEFAULT_CONTROLLER_ID} as prefix for * {@link Target#getControllerId()}. * * @param number * of {@link Target}s to create * * @return {@link List} of {@link Target} entities */ public List<Target> createTargets(final int number) { final List<TargetCreate> targets = Lists.newArrayListWithExpectedSize(number); for (int i = 0; i < number; i++) { targets.add(entityFactory.target().create().controllerId(DEFAULT_CONTROLLER_ID + i)); } return targetManagement.create(targets); }
private ActionStatus checkAndLogDownload(final HttpServletRequest request, final Target target, final Long module) { final Action action = controllerManagement .getActionForDownloadByTargetAndSoftwareModule(target.getControllerId(), module) .orElseThrow(() -> new SoftwareModuleNotAssignedToTargetException(module, target.getControllerId())); final String range = request.getHeader("Range"); String message; if (range != null) { message = RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: " + request.getRequestURI(); } else { message = RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI(); } return controllerManagement.addInformationalActionStatus( entityFactory.actionStatus().create(action.getId()).status(Status.DOWNLOAD).message(message)); }
@Override public ResponseEntity<MgmtDistributionSet> updateDistributionSet( @PathVariable("distributionSetId") final Long distributionSetId, @RequestBody final MgmtDistributionSetRequestBodyPut toUpdate) { final DistributionSet updated = distributionSetManagement.update(entityFactory.distributionSet() .update(distributionSetId).name(toUpdate.getName()).description(toUpdate.getDescription()) .version(toUpdate.getVersion()).requiredMigrationStep(toUpdate.isRequiredMigrationStep())); final MgmtDistributionSet response = MgmtDistributionSetMapper.toResponse(updated); MgmtDistributionSetMapper.addLinks(updated, response); return ResponseEntity.ok(response); }
static List<TagCreate> mapTagFromRequest(final EntityFactory entityFactory, final Collection<MgmtTagRequestBodyPut> tags) { return tags.stream() .map(tagRest -> entityFactory.tag().create().name(tagRest.getName()) .description(tagRest.getDescription()).colour(tagRest.getColour())) .collect(Collectors.toList()); }
@Override public ResponseEntity<MgmtSoftwareModuleType> updateSoftwareModuleType( @PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId, @RequestBody final MgmtSoftwareModuleTypeRequestBodyPut restSoftwareModuleType) { final SoftwareModuleType updatedSoftwareModuleType = softwareModuleTypeManagement.update(entityFactory .softwareModuleType().update(softwareModuleTypeId).description(restSoftwareModuleType.getDescription()) .colour(restSoftwareModuleType.getColour())); return ResponseEntity.ok(MgmtSoftwareModuleTypeMapper.toResponse(updatedSoftwareModuleType)); }
static List<SoftwareModuleMetadataCreate> fromRequestSwMetadata(final EntityFactory entityFactory, final Long softwareModuleId, final Collection<MgmtSoftwareModuleMetadata> metadata) { if (metadata == null) { return Collections.emptyList(); } return metadata.stream() .map(metadataRest -> entityFactory.softwareModuleMetadata().create(softwareModuleId) .key(metadataRest.getKey()).value(metadataRest.getValue()) .targetVisible(metadataRest.isTargetVisible())) .collect(Collectors.toList()); }
@Override public ResponseEntity<MgmtDistributionSetType> updateDistributionSetType( @PathVariable("distributionSetTypeId") final Long distributionSetTypeId, @RequestBody final MgmtDistributionSetTypeRequestBodyPut restDistributionSetType) { final DistributionSetType updated = distributionSetTypeManagement.update(entityFactory.distributionSetType() .update(distributionSetTypeId).description(restDistributionSetType.getDescription()) .colour(restDistributionSetType.getColour())); final MgmtDistributionSetType reponse = MgmtDistributionSetTypeMapper.toResponse(updated); MgmtDistributionSetTypeMapper.addLinks(reponse); return ResponseEntity.ok(reponse); }
@Override public ResponseEntity<MgmtSoftwareModule> updateSoftwareModule( @PathVariable("softwareModuleId") final Long softwareModuleId, @RequestBody final MgmtSoftwareModuleRequestBodyPut restSoftwareModule) { final SoftwareModule module = softwareModuleManagement .update(entityFactory.softwareModule().update(softwareModuleId) .description(restSoftwareModule.getDescription()).vendor(restSoftwareModule.getVendor())); final MgmtSoftwareModule response = MgmtSoftwareModuleMapper.toResponse(module); MgmtSoftwareModuleMapper.addLinks(module, response); return ResponseEntity.ok(response); }
static RolloutCreate fromRequest(final EntityFactory entityFactory, final MgmtRolloutRestRequestBody restRequest, final DistributionSet distributionSet) { return entityFactory.rollout().create().name(restRequest.getName()).description(restRequest.getDescription()) .set(distributionSet).targetFilterQuery(restRequest.getTargetFilterQuery()) .actionType(MgmtRestModelMapper.convertActionType(restRequest.getType())) .forcedTime(restRequest.getForcetime()).startAt(restRequest.getStartAt()); }
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; }
static List<MetaData> fromRequestDsMetadata(final List<MgmtMetadata> metadata, final EntityFactory entityFactory) { if (metadata == null) { return Collections.emptyList(); } return metadata.stream() .map(metadataRest -> entityFactory.generateDsMetadata(metadataRest.getKey(), metadataRest.getValue())) .collect(Collectors.toList()); }
@Override public ResponseEntity<MgmtTag> updateDistributionSetTag( @PathVariable("distributionsetTagId") final Long distributionsetTagId, @RequestBody final MgmtTagRequestBodyPut restDSTagRest) { final DistributionSetTag distributionSetTag = distributionSetTagManagement .update(entityFactory.tag().update(distributionsetTagId).name(restDSTagRest.getName()) .description(restDSTagRest.getDescription()).colour(restDSTagRest.getColour())); final MgmtTag response = MgmtTagMapper.toResponse(distributionSetTag); MgmtTagMapper.addLinks(distributionSetTag, response); return ResponseEntity.ok(response); }
/** * Finds {@link SoftwareModuleType} in repository with given * {@link SoftwareModuleType#getKey()} or creates if it does not exist yet. * * @param key * {@link SoftwareModuleType#getKey()} * @param maxAssignments * {@link SoftwareModuleType#getMaxAssignments()} * * @return persisted {@link SoftwareModuleType} */ public SoftwareModuleType findOrCreateSoftwareModuleType(final String key, final int maxAssignments) { return softwareModuleTypeManagement.getByKey(key) .orElseGet(() -> softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create() .key(key).name(key).description(LOREM.words(10)).maxAssignments(maxAssignments))); }
@Override public ResponseEntity<MgmtSoftwareModuleMetadata> updateMetadata( @PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("metadataKey") final String metadataKey, @RequestBody final MgmtSoftwareModuleMetadataBodyPut metadata) { final SoftwareModuleMetadata updated = softwareModuleManagement .updateMetaData(entityFactory.softwareModuleMetadata().update(softwareModuleId, metadataKey) .value(metadata.getValue()).targetVisible(metadata.isTargetVisible())); return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponseSwMetadata(updated)); }
/** * Creates {@link DistributionSetType} in repository. * * @param dsTypeKey * {@link DistributionSetType#getKey()} * @param dsTypeName * {@link DistributionSetType#getName()} * * @return persisted {@link DistributionSetType} */ public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName) { return distributionSetTypeManagement.getByKey(dsTypeKey) .orElseGet(() -> distributionSetTypeManagement.create(entityFactory.distributionSetType().create() .key(dsTypeKey).name(dsTypeName).description(LOREM.words(10)).colour("black"))); }
/** * Creates {@link SoftwareModule} with {@link #DEFAULT_VENDOR} and * {@link #DEFAULT_VERSION} and random generated * {@link Target#getDescription()} in the repository. * * @param typeKey * of the {@link SoftwareModuleType} * @param prefix * added to name and version * * @return persisted {@link SoftwareModule}. */ public SoftwareModule createSoftwareModule(final String typeKey, final String prefix) { return softwareModuleManagement.create(entityFactory.softwareModule().create() .type(findOrCreateSoftwareModuleType(typeKey)).name(prefix + typeKey).version(prefix + DEFAULT_VERSION) .description(LOREM.words(10)).vendor(DEFAULT_VENDOR)); }
private Rollout saveRollout() { final Long distributionId = (Long) distributionSet.getValue(); final int amountGroup = Integer.parseInt(noOfGroups.getValue()); final int errorThresholdPercent = getErrorThresholdPercentage(amountGroup); final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder() .successAction(RolloutGroupSuccessAction.NEXTGROUP, null) .successCondition(RolloutGroupSuccessCondition.THRESHOLD, triggerThreshold.getValue()) .errorCondition(RolloutGroupErrorCondition.THRESHOLD, String.valueOf(errorThresholdPercent)) .errorAction(RolloutGroupErrorAction.PAUSE, null).build(); final RolloutCreate rolloutCreate = entityFactory.rollout().create().name(rolloutName.getValue()) .description(description.getValue()).set(distributionId).targetFilterQuery(getTargetFilterQuery()) .actionType(getActionType()).forcedTime(getForcedTimeStamp()); if (AutoStartOptionGroupLayout.AutoStartOption.AUTO_START.equals(getAutoStartOption())) { rolloutCreate.startAt(System.currentTimeMillis()); } if (AutoStartOptionGroupLayout.AutoStartOption.SCHEDULED.equals(getAutoStartOption())) { rolloutCreate.startAt(getScheduledStartTime()); } if (isNumberOfGroups()) { return rolloutManagement.create(rolloutCreate, amountGroup, conditions); } else if (isGroupsDefinition()) { final List<RolloutGroupCreate> groups = defineGroupsLayout.getSavedRolloutGroups(); return rolloutManagement.create(rolloutCreate, groups, conditions); } throw new IllegalStateException("Either of the Tabs must be selected"); }
@Override public ResponseEntity<MgmtMetadata> updateMetadata(@PathVariable("distributionSetId") final Long distributionSetId, @PathVariable("metadataKey") final String metadataKey, @RequestBody final MgmtMetadataBodyPut metadata) { // check if distribution set exists otherwise throw exception // immediately final DistributionSetMetadata updated = distributionSetManagement.updateMetaData(distributionSetId, entityFactory.generateDsMetadata(metadataKey, metadata.getValue())); return ResponseEntity.ok(MgmtDistributionSetMapper.toResponseDsMetadata(updated)); }
/** * @param controllerId * of the target * @return persisted {@link Target} */ public Target createTarget(final String controllerId) { final Target target = targetManagement.create(entityFactory.target().create().controllerId(controllerId)); assertThat(target.getCreatedBy()).isNotNull(); assertThat(target.getCreatedAt()).isNotNull(); assertThat(target.getLastModifiedBy()).isNotNull(); assertThat(target.getLastModifiedAt()).isNotNull(); assertThat(target.getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN); return target; }
private ActionStatus checkAndLogDownload(final HttpServletRequest request, final Target target, final Long module) { final Action action = controllerManagement .getActionForDownloadByTargetAndSoftwareModule(target.getControllerId(), module) .orElseThrow(() -> new SoftwareModuleNotAssignedToTargetException(module, target.getControllerId())); final String range = request.getHeader("Range"); String message; if (range != null) { message = RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: " + request.getRequestURI(); } else { message = RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI(); } return controllerManagement.addInformationalActionStatus( entityFactory.actionStatus().create(action.getId()).status(Status.DOWNLOAD).message(message)); }