Skip to content

Feature offline deployments - #563

Merged
kaizimmerm merged 6 commits into
eclipse-hawkbit:masterfrom
bosch-io:feature_offline_deployments
Jul 27, 2017
Merged

kaizimmerm merged 6 commits into
eclipse-hawkbit:masterfrom
bosch-io:feature_offline_deployments

Conversation

@kaizimmerm

@kaizimmerm kaizimmerm commented Jul 18, 2017 •

Copy link
Copy Markdown
Contributor

Support for offline deployment in repository and Management API.

That comes in handy for several scenarios, e.g.

  • Import existing installation history in migration scenarios to rollouts.
  • Complete action history in case installations on a rollouts managed device have not been executed by rollouts itself (e.g. manual offline flashing).

Feature overview:

  • DS assignments on to a target through Management API can be executed including an successful installation result in one request.
  • installed DS is set accordingly.
  • The server checks that currently no installation is running and refuses the request if so.
  • Actions of such a request are put on top of the list as it is today with regular actions.

While at it I fixed a bug as well where assign DS response worked different on target and DS resources.

Reviewers: @schabdo @Jonkno

/**
* Method registers an "offline" assignment, i.e. adds a completed action
* for the given {@link DistributionSet} to the given {@link Target}s.
*

@schabdo schabdo Jul 24, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: manged => managed

* @return the assignment result
*
* @throws IncompleteDistributionSetException
* if mandatory {@link SoftwareModuleType} are not assigned as

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: define => defined

* Method registers an "offline" assignment, i.e. adds a completed action
* for the given {@link DistributionSet} to the given {@link Target}s.
*
* The handling differs to hawkBit manged updates my means that:<br/>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use a ordered list, you do not have to format it manually:

<ol type="A">
  <li>it ignores targets completely that are in {@link TargetUpdateStatus#PENDING}</li>
  <li>it creates completed actions</li>
   ....
</ol>

@Param("set") JpaDistributionSet set, @Param("lastModifiedAt") Long modifiedAt,
@Param("lastModifiedBy") String modifiedBy, @Param("targets") Collection<Long> targets);

/**

@schabdo schabdo Jul 24, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better:

Sets {@link JpaTarget#getAssignedDistributionSet()}, {@link JpaTarget#getInstalledDistributionSet()} and
{@link JpaTarget#getInstallationDate()}.


@Test
@Description("Simple offline deployment of a distribution set to a list of targets. Verifies that offline assigment "
+ "is correctly executed for targets that do not have a runnign update already. Those are ignored.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: runnign => running

// execute multiple statements we take the target only into account if
// the requested operation is no duplicate of a previous one
final List<JpaTarget> targets = Lists.partition(controllerIDs, Constants.MAX_ENTRIES_IN_STATEMENT).stream()
.map(ids -> targetRepository

@schabdo schabdo Jul 24, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the offline capability there are a lot of branches within the code now. This makes it hard to maintain and you'll get at lot of duplications. Have a look only at the public methods: All of them pass through a boolean to state whether it is an offline or online update (indicator for violating SRP). I suggest to either split this class into two internal classes (e.g. JpaOnlineDeploymentManagement and JpaOfflineDeploymentManagement) or make use of the strategy-pattern for online/offline case e.g.:

interface UpdateStrategy { // maybe there is a better name for it

    List<JpaTarget> findTarget(final List<String> controllerIDs, final long setId);
    void updateTargetStatus(final JpaDistributionSet set, final List<List<Long>> targetIds, final String currentUser);
    Set<Long> findTargetIdToCancel(List<List<Long>> targetIds);
    Status getActionStatus();
}

class OnlineUpdate implements UpdateStrategy{}
class OfflineUpdate implements UpdateStrategy{}

Later on in the implementation you won't have an if/else statement and only call:

strategy.findTarget(ids, set.getId());

Instead of:

final List<JpaTarget> targets;
        if (offline) {
            targets = Lists.partition(controllerIDs, Constants.MAX_ENTRIES_IN_STATEMENT).stream()
                    .map(ids -> targetRepository.findAll(SpecificationsBuilder.combineWithAnd(Arrays.asList(
                            TargetSpecifications.hasControllerIdAndAssignedDistributionSetIdNot(ids, set.getId()),
                            TargetSpecifications.notEqualToTargetUpdateStatus(TargetUpdateStatus.PENDING)))))
                    .flatMap(List::stream).collect(Collectors.toList());
        } else {
            targets = Lists.partition(controllerIDs, Constants.MAX_ENTRIES_IN_STATEMENT).stream()
                    .map(ids -> targetRepository.findAll(
                            TargetSpecifications.hasControllerIdAndAssignedDistributionSetIdNot(ids, set.getId())))
                    .flatMap(List::stream).collect(Collectors.toList());
        }

Signed-off-by: kaizimmerm <[email protected]>
return ResponseEntity
.ok(MgmtDistributionSetMapper.toResponse(this.deployManagament.assignDistributionSet(distributionSetId,
targetIds.stream()
.map(t -> new TargetWithActionType(t.getId(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use a descriptive value for the the parameter t (e.g. targetId)

import org.springframework.context.ApplicationEventPublisher;

/**
* @author kaizimmerm

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove author and add javadoc to class

*
* @param controllerIDs
* as provided by repository caller
* @param setId

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better call it distributionSetId

/**
* Update status and DS fields of given target.
*
* @param set

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better call it distributionSetId here and in the method signature

/**
* Cancels actions that can be canceled (i.e.
* {@link DistributionSet#isRequiredMigrationStep() is <code>false</code>})
* as a result of the new assignment and returns all {@link Target}s whers

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: where

return activeActions.stream().map(action -> {
action.setStatus(Status.CANCELING);
// document that the status has been retrieved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove line or move comment down

public DistributionSetAssignmentResult offlineAssignedDistributionSet(final Long dsID,
final Collection<String> controllerIDs) {
return assignDistributionSetToTargets(dsID, controllerIDs.stream()
.map(t -> new TargetWithActionType(t, ActionType.FORCED, -1)).collect(Collectors.toList()), null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename t to targetId or controllerId

return assignDistributionSetToTargets(dsID, targetIDs.stream()
.map(t -> new TargetWithActionType(t, actionType, forcedTimestamp)).collect(Collectors.toList()), null);
return assignDistributionSetToTargets(dsID, controllerIDs.stream()
.map(t -> new TargetWithActionType(t, actionType, forcedTimestamp)).collect(Collectors.toList()), null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename t to targetId or controllerId

Signed-off-by: kaizimmerm <[email protected]>
@kaizimmerm
kaizimmerm merged commit e2ca4cf into eclipse-hawkbit:master Jul 27, 2017
@kaizimmerm
kaizimmerm deleted the feature_offline_deployments branch July 27, 2017 15:29
@kaizimmerm kaizimmerm added this to the 0.2.0M4 milestone Feb 7, 2018
AmmarBikic pushed a commit to bosch-io/hawkbit that referenced this pull request Oct 2, 2020
* Repository support offline deployments.

Signed-off-by: kaizimmerm <[email protected]>

* Add offline assignment to Management API.

Signed-off-by: kaizimmerm <[email protected]>

* DsAssignmentStrategy introduced.

Signed-off-by: kaizimmerm <[email protected]>

* Fixed JavaDoc.

Signed-off-by: kaizimmerm <[email protected]>

* Readibility improved.

Signed-off-by: kaizimmerm <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants