add example mgmt-api-client powered by feign and spring-cloud.
Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com>
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.api.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.RestConstants;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRequestBodyPost;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest;
|
||||
|
||||
import feign.Headers;
|
||||
import feign.RequestLine;
|
||||
|
||||
/**
|
||||
* Client binding for the Distribution resource of the management API.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface DistributionSetResource {
|
||||
|
||||
/**
|
||||
* Creates a list of distribution sets.
|
||||
*
|
||||
* @param sets
|
||||
* the request body java bean containing the necessary attributes
|
||||
* for creating a distribution set.
|
||||
* @return the list of targets which have been created
|
||||
*/
|
||||
@RequestLine("POST " + RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)
|
||||
@Headers("Content-Type: application/json")
|
||||
DistributionSetsRest createDistributionSets(final List<DistributionSetRequestBodyPost> sets);
|
||||
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.api.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.RestConstants;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.AssignedDistributionSetRequestBody;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.DistributionSetTagAssigmentResultRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetsRest;
|
||||
|
||||
import feign.Headers;
|
||||
import feign.Param;
|
||||
import feign.RequestLine;
|
||||
|
||||
/**
|
||||
* Client binding for the DistributionSetTag resource of the management API.
|
||||
*/
|
||||
public interface DistrubutionSetTagResource {
|
||||
|
||||
/**
|
||||
* Retrieves a single distributionset tag based on the given ID.
|
||||
*
|
||||
* @param dsTagId
|
||||
* the ID of the distributionset tag to retrieve
|
||||
* @return a deserialized java bean containing the attributes of the
|
||||
* returned distributionset tag
|
||||
*/
|
||||
@RequestLine("GET " + RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/{dsTagId}")
|
||||
TagRest getDistributionSetTag(@Param("dsTagId") Long dsTagId);
|
||||
|
||||
/**
|
||||
* Creates a list of distributionset tags.
|
||||
*
|
||||
* @param tags
|
||||
* the tags to be created
|
||||
* @return the created tag list
|
||||
*/
|
||||
@RequestLine("POST " + RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING)
|
||||
@Headers("Content-Type: application/json")
|
||||
TagsRest createDistributionSetTags(List<TagRequestBodyPut> tags);
|
||||
|
||||
/**
|
||||
* Update attributes of a distributionset tag.
|
||||
*
|
||||
* @param dsTagId
|
||||
* the distributionset tag id to be updated
|
||||
* @param tag
|
||||
* the request body
|
||||
* @return the updated distributionset tag
|
||||
*/
|
||||
@RequestLine("PUT " + RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/{dsTagId}")
|
||||
@Headers("Content-Type: application/json")
|
||||
TagRest updateDistributionSetTag(@Param("dsTagId") Long dsTagId, TagRequestBodyPut tag);
|
||||
|
||||
/**
|
||||
* Deletes given distributionset tag on given ID.
|
||||
*
|
||||
* @param dsTagId
|
||||
* to be deleted
|
||||
*/
|
||||
@RequestLine("DELETE " + RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/{dsTagId}")
|
||||
void deleteDistributionSetTag(@Param("dsTagId") final Long dsTagId);
|
||||
|
||||
/**
|
||||
* Retrieves a all assigned targets on the given distributionset tag id.
|
||||
*
|
||||
* @param dsTagId
|
||||
* the ID of the distributionset tag to retrieve
|
||||
* @return a list of targets
|
||||
*/
|
||||
@RequestLine("GET " + RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING
|
||||
+ RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING)
|
||||
DistributionSetsRest getAssignedDistributionSets(@Param("dsTagId") final Long dsTagId);
|
||||
|
||||
/**
|
||||
* Toggle the tag assignment all assigned targets will be unassigned and all
|
||||
* unassigned targets will be assigned.
|
||||
*
|
||||
* @param dsTagId
|
||||
* the ID of the distributionset tag to toggle
|
||||
* @param assignedTargetRequestBodies
|
||||
* a list of controller ids
|
||||
* @return a list of assigned and unassigned targets
|
||||
*/
|
||||
@RequestLine("POST " + RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING
|
||||
+ RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING + "/toggleTagAssignment")
|
||||
@Headers("Content-Type: application/json")
|
||||
DistributionSetTagAssigmentResultRest toggleTagAssignment(@Param("dsTagId") final Long dsTagId,
|
||||
final List<AssignedDistributionSetRequestBody> assignedTargetRequestBodies);
|
||||
|
||||
/**
|
||||
* Assign targets to a given distributionset tag id.
|
||||
*
|
||||
* @param dsTagId
|
||||
* the ID of the distributionset tag to add the targets
|
||||
* @param assignedTargetRequestBodies
|
||||
* a list of controller ids
|
||||
* @return a list of assigned targets
|
||||
*/
|
||||
@RequestLine("POST " + RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING
|
||||
+ RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING)
|
||||
@Headers("Content-Type: application/json")
|
||||
TargetsRest assignDistributionSets(@Param("dsTagId") final Long dsTagId,
|
||||
final List<AssignedDistributionSetRequestBody> assignedTargetRequestBodies);
|
||||
|
||||
/**
|
||||
* Unassign targets to a given distributionset tag id.
|
||||
*
|
||||
* @param dsTagId
|
||||
* the ID of the distributionset tag to add the targets
|
||||
*/
|
||||
@RequestLine("DELETE " + RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING
|
||||
+ RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING)
|
||||
void unassignDistributionSets(@Param("dsTagId") final Long dsTagId);
|
||||
|
||||
/**
|
||||
* Unassign one target to a given distributionset tag id.
|
||||
*
|
||||
* @param dsTagId
|
||||
* the ID of the distributionset tag to add the targets param
|
||||
* @param dsId
|
||||
* the distributionset id
|
||||
*/
|
||||
@RequestLine("DELETE " + RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING
|
||||
+ RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING + "/{dsId}")
|
||||
void unassignDistributionSet(@Param("dsTagId") final Long dsTagId, @Param("dsId") final Long dsId);
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.api.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetPagedList;
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetRequestBody;
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetsRest;
|
||||
|
||||
import feign.Headers;
|
||||
import feign.Param;
|
||||
import feign.RequestLine;
|
||||
|
||||
/**
|
||||
* Client binding for the Target resource of the management API.
|
||||
*/
|
||||
public interface TargetResource {
|
||||
|
||||
/**
|
||||
* Retrieves a single target based on the given ID.
|
||||
*
|
||||
* @param targetId
|
||||
* the ID of the target to retrieve
|
||||
* @return a deserialized java bean containing the attributes of the
|
||||
* returned target
|
||||
*/
|
||||
@RequestLine("GET /rest/v1/targets/{targetId}")
|
||||
TargetRest getTarget(@Param("targetId") final String targetId);
|
||||
|
||||
/**
|
||||
* Paged query of targets resource.
|
||||
*
|
||||
* @param pagingOffsetParam
|
||||
* of the paged query
|
||||
* @param pagingLimitParam
|
||||
* of the paged query
|
||||
* @return paged list of target entries
|
||||
*/
|
||||
@RequestLine("GET /rest/v1/targets?offset={pagingOffsetParam}&limit={pagingLimitParam}")
|
||||
TargetPagedList getTargets(@Param("pagingOffsetParam") int pagingOffsetParam,
|
||||
@Param("pagingLimitParam") int pagingLimitParam);
|
||||
|
||||
/**
|
||||
* Paged query of targets resource with default offset and limit.
|
||||
*
|
||||
* @return paged list of target entries
|
||||
*/
|
||||
@RequestLine("GET /rest/v1/targets")
|
||||
TargetPagedList getTargets();
|
||||
|
||||
/**
|
||||
* Deletes given target based on given ID.
|
||||
*
|
||||
* @param targetId
|
||||
* to be deleted
|
||||
*/
|
||||
@RequestLine("DELETE /rest/v1/targets/{targetId}")
|
||||
void deleteTarget(@Param("targetId") final String targetId);
|
||||
|
||||
/**
|
||||
* Creates a list of targets.
|
||||
*
|
||||
* @param targets
|
||||
* the request body java bean containing the necessary attributes
|
||||
* for creating a target.
|
||||
* @return the list of targets which have been created
|
||||
*/
|
||||
@RequestLine("POST /rest/v1/targets/")
|
||||
@Headers("Content-Type: application/json")
|
||||
TargetsRest createTargets(List<TargetRequestBody> targets);
|
||||
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.api.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.RestConstants;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.AssignedTargetRequestBody;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TargetTagAssigmentResultRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetsRest;
|
||||
|
||||
import feign.Headers;
|
||||
import feign.Param;
|
||||
import feign.RequestLine;
|
||||
|
||||
/**
|
||||
* Client binding for the Target resource of the management API.
|
||||
*/
|
||||
public interface TargetTagResource {
|
||||
|
||||
/**
|
||||
* Retrieves a single target tag based on the given ID.
|
||||
*
|
||||
* @param targetTagId
|
||||
* the ID of the target tag to retrieve
|
||||
* @return a deserialized java bean containing the attributes of the
|
||||
* returned target tag
|
||||
*/
|
||||
@RequestLine("GET " + RestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/{targetTagId}")
|
||||
TagRest getTargetTag(@Param("targetTagId") Long targetTagId);
|
||||
|
||||
/**
|
||||
* Creates a list of target tags.
|
||||
*
|
||||
* @param tags
|
||||
* the tags to be created
|
||||
* @return the created tag list
|
||||
*/
|
||||
@RequestLine("POST " + RestConstants.TARGET_TAG_V1_REQUEST_MAPPING)
|
||||
@Headers("Content-Type: application/json")
|
||||
TagsRest createTargetTag(List<TagRequestBodyPut> tags);
|
||||
|
||||
/**
|
||||
* Update attributes of a target tag.
|
||||
*
|
||||
* @param targetTagId
|
||||
* the target tag id to be updated
|
||||
* @param tag
|
||||
* the request body
|
||||
* @return the updated target tag
|
||||
*/
|
||||
@RequestLine("PUT " + RestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/{targetTagId}")
|
||||
@Headers("Content-Type: application/json")
|
||||
TagRest updateTagretTag(@Param("targetTagId") Long targetTagId, TagRequestBodyPut tag);
|
||||
|
||||
/**
|
||||
* Deletes given target tag on given ID.
|
||||
*
|
||||
* @param targetTagId
|
||||
* to be deleted
|
||||
*/
|
||||
@RequestLine("DELETE " + RestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/{targetTagId}")
|
||||
void deleteTargetTag(@Param("targetTagId") final Long targetTagId);
|
||||
|
||||
/**
|
||||
* Retrieves a all assigned targets on the given target tag id.
|
||||
*
|
||||
* @param targetTagId
|
||||
* the ID of the target tag to retrieve
|
||||
* @return a list of targets
|
||||
*/
|
||||
@RequestLine("GET " + RestConstants.TARGET_TAG_V1_REQUEST_MAPPING
|
||||
+ RestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING)
|
||||
TargetsRest getAssignedTargets(@Param("targetTagId") final Long targetTagId);
|
||||
|
||||
/**
|
||||
* Toggle the tag assignment all assigned targets will be unassigned and all
|
||||
* unassigned targets will be assigned.
|
||||
*
|
||||
* @param targetTagId
|
||||
* the ID of the target tag to toggle
|
||||
* @param assignedTargetRequestBodies
|
||||
* a list of controller ids
|
||||
* @return a list of assigned and unassigned targets
|
||||
*/
|
||||
@RequestLine("POST " + RestConstants.TARGET_TAG_V1_REQUEST_MAPPING
|
||||
+ RestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING + "/toggleTagAssignment")
|
||||
@Headers("Content-Type: application/json")
|
||||
TargetTagAssigmentResultRest toggleTagAssignment(@Param("targetTagId") final Long targetTagId,
|
||||
final List<AssignedTargetRequestBody> assignedTargetRequestBodies);
|
||||
|
||||
/**
|
||||
* Assign targets to a given target tag id.
|
||||
*
|
||||
* @param targetTagId
|
||||
* the ID of the target tag to add the targets
|
||||
* @param assignedTargetRequestBodies
|
||||
* a list of controller ids
|
||||
* @return a list of assigned targets
|
||||
*/
|
||||
@RequestLine("POST " + RestConstants.TARGET_TAG_V1_REQUEST_MAPPING
|
||||
+ RestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING)
|
||||
@Headers("Content-Type: application/json")
|
||||
TargetsRest assignTargets(@Param("targetTagId") final Long targetTagId,
|
||||
final List<AssignedTargetRequestBody> assignedTargetRequestBodies);
|
||||
|
||||
/**
|
||||
* Unassign targets to a given target tag id.
|
||||
*
|
||||
* @param targetTagId
|
||||
* the ID of the target tag to add the targets
|
||||
*/
|
||||
@RequestLine("DELETE " + RestConstants.TARGET_TAG_V1_REQUEST_MAPPING
|
||||
+ RestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING)
|
||||
void unassignTargets(@Param("targetTagId") final Long targetTagId);
|
||||
|
||||
/**
|
||||
* Unassign one target to a given target tag id.
|
||||
*
|
||||
* @param targetTagId
|
||||
* the ID of the target tag to add the targets param
|
||||
* @param controllerId
|
||||
* the controller id
|
||||
*/
|
||||
@RequestLine("DELETE " + RestConstants.TARGET_TAG_V1_REQUEST_MAPPING
|
||||
+ RestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING + "/{controllerId}")
|
||||
void unassignTarget(@Param("targetTagId") final Long targetTagId, @Param("controllerId") final String controllerId);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client;
|
||||
|
||||
import org.eclipse.hawkbit.mgmt.client.scenarios.CreateStartedRolloutExample;
|
||||
import org.eclipse.hawkbit.mgmt.client.scenarios.GettingStartedDefaultScenario;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.netflix.feign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import feign.Contract;
|
||||
import feign.auth.BasicAuthRequestInterceptor;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableFeignClients
|
||||
@EnableConfigurationProperties(ClientConfigurationProperties.class)
|
||||
public class Application implements CommandLineRunner {
|
||||
|
||||
@Autowired
|
||||
private ClientConfigurationProperties configuration;
|
||||
|
||||
@Autowired
|
||||
private GettingStartedDefaultScenario gettingStarted;
|
||||
|
||||
@Autowired
|
||||
private CreateStartedRolloutExample gettingStartedRolloutScenario;
|
||||
|
||||
public static void main(final String[] args) {
|
||||
new SpringApplicationBuilder().showBanner(false).sources(Application.class).run(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(final String... args) throws Exception {
|
||||
if (containsArg("--createrollout", args)) {
|
||||
// run the create and start rollout example
|
||||
gettingStartedRolloutScenario.run();
|
||||
} else {
|
||||
// run the getting started scenario which creates a setup of
|
||||
// distribution set and software modules to be used
|
||||
gettingStarted.run();
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public BasicAuthRequestInterceptor basicAuthRequestInterceptor() {
|
||||
return new BasicAuthRequestInterceptor(configuration.getUsername(), configuration.getPassword());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ApplicationJsonRequestHeaderInterceptor jsonHeaderInterceptor() {
|
||||
return new ApplicationJsonRequestHeaderInterceptor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Contract feignContract() {
|
||||
return new IgnoreMultipleConsumersProducersSpringMvcContract();
|
||||
}
|
||||
|
||||
private boolean containsArg(final String containsArg, final String... args) {
|
||||
for (final String arg : args) {
|
||||
if (arg.equalsIgnoreCase(containsArg)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import feign.RequestInterceptor;
|
||||
import feign.RequestTemplate;
|
||||
|
||||
/**
|
||||
* An feign request interceptor to set the defined {@code Accept} and
|
||||
* {@code Content-Type} headers for each request to {@code application/json}.
|
||||
*/
|
||||
public class ApplicationJsonRequestHeaderInterceptor implements RequestInterceptor {
|
||||
|
||||
@Override
|
||||
public void apply(final RequestTemplate template) {
|
||||
template.header("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
template.header("Content-Type", MediaType.APPLICATION_JSON_VALUE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Configuration bean which holds the configuration of the client e.g. the base
|
||||
* URL of the hawkbit-server and the credentials to use the RESTful Management
|
||||
* API.
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "hawkbit")
|
||||
public class ClientConfigurationProperties {
|
||||
|
||||
private String url = "localhost:8080";
|
||||
private String username = "admin";
|
||||
private String password = "admin"; // NOSONAR this password is only used for
|
||||
// examples
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(final String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(final String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(final String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.netflix.feign.support.SpringMvcContract;
|
||||
|
||||
import feign.MethodMetadata;
|
||||
|
||||
/**
|
||||
* Own implementation of the {@link SpringMvcContract} which catches the
|
||||
* {@link IllegalStateException} which occurs due multiple produces and consumes
|
||||
* values in the request-mapping
|
||||
* annoation.https://github.com/spring-cloud/spring-cloud-netflix/issues/808
|
||||
*/
|
||||
public class IgnoreMultipleConsumersProducersSpringMvcContract extends SpringMvcContract {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory
|
||||
.getLogger(IgnoreMultipleConsumersProducersSpringMvcContract.class);
|
||||
|
||||
@Override
|
||||
protected void processAnnotationOnMethod(final MethodMetadata data, final Annotation methodAnnotation,
|
||||
final Method method) {
|
||||
try {
|
||||
super.processAnnotationOnMethod(data, methodAnnotation, method);
|
||||
} catch (final IllegalStateException e) {
|
||||
// ignore illegalstateexception here because it's thrown because of
|
||||
// multiple consumers and produces, see
|
||||
// https://github.com/spring-cloud/spring-cloud-netflix/issues/808
|
||||
LOGGER.trace(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client.resource;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.api.DistributionSetRestApi;
|
||||
import org.springframework.cloud.netflix.feign.FeignClient;
|
||||
|
||||
/**
|
||||
* Client binding for the DistributionSet resource of the management API.
|
||||
*/
|
||||
@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/distributionsets")
|
||||
public interface DistributionSetResourceClient extends DistributionSetRestApi {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client.resource;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.api.DistributionSetTagRestApi;
|
||||
import org.springframework.cloud.netflix.feign.FeignClient;
|
||||
|
||||
/**
|
||||
* Client binding for the DistributionSetTag resource of the management API.
|
||||
*/
|
||||
@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/distributionsettags")
|
||||
public interface DistributionSetTagResourceClient extends DistributionSetTagRestApi {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client.resource;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.api.DistributionSetTypeRestApi;
|
||||
import org.springframework.cloud.netflix.feign.FeignClient;
|
||||
|
||||
/**
|
||||
* Client binding for the DistributionSetType resource of the management API.
|
||||
*
|
||||
*/
|
||||
@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/distributionsettypes")
|
||||
public interface DistributionSetTypeResourceClient extends DistributionSetTypeRestApi {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client.resource;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.api.RolloutRestApi;
|
||||
import org.springframework.cloud.netflix.feign.FeignClient;
|
||||
|
||||
/**
|
||||
* Client binding for the Rollout resource of the management API.
|
||||
*/
|
||||
@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/rollouts")
|
||||
public interface RolloutResourceClient extends RolloutRestApi {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client.resource;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.api.SoftwareModuleRestAPI;
|
||||
import org.springframework.cloud.netflix.feign.FeignClient;
|
||||
|
||||
/**
|
||||
* Client binding for the SoftwareModule resource of the management API.
|
||||
*/
|
||||
@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/softwaremodules")
|
||||
public interface SoftwareModuleResourceClient extends SoftwareModuleRestAPI {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client.resource;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.api.SoftwareModuleTypeRestApi;
|
||||
import org.springframework.cloud.netflix.feign.FeignClient;
|
||||
|
||||
/**
|
||||
* Client binding for the oftwareModuleType resource of the management API.
|
||||
*/
|
||||
@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/softwaremoduletypes")
|
||||
public interface SoftwareModuleTypeResourceClient extends SoftwareModuleTypeRestApi {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client.resource;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.api.TargetRestApi;
|
||||
import org.springframework.cloud.netflix.feign.FeignClient;
|
||||
|
||||
/**
|
||||
* Client binding for the Target resource of the management API.
|
||||
*/
|
||||
@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/targets")
|
||||
public interface TargetResourceClient extends TargetRestApi {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client.resource;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.api.TargetTagRestApi;
|
||||
import org.springframework.cloud.netflix.feign.FeignClient;
|
||||
|
||||
/**
|
||||
* Client binding for the TargetTag resource of the management API.
|
||||
*/
|
||||
@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/targettags")
|
||||
public interface TargetTagResourceClient extends TargetTagRestApi {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client.resource.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRequestBodyPost;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
*
|
||||
* Builder pattern for building {@link DistributionSetRequestBodyPost}.
|
||||
*
|
||||
* @author Jonathan Knoblauch
|
||||
*
|
||||
*/
|
||||
public class DistributionSetBuilder {
|
||||
|
||||
private String name;
|
||||
private String version;
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name of the distribution set
|
||||
* @return the builder itself
|
||||
*/
|
||||
public DistributionSetBuilder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param version
|
||||
* the version of the distribution set
|
||||
* @return the builder itself
|
||||
*/
|
||||
public DistributionSetBuilder version(final String version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type
|
||||
* the distribution set type name for this distribution set
|
||||
* @return the builder itself
|
||||
*/
|
||||
public DistributionSetBuilder type(final String type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a list with a single entry of
|
||||
* {@link DistributionSetRequestBodyPost} which can directly be used to post
|
||||
* on the RESTful-API.
|
||||
*
|
||||
* @return a single entry list of {@link DistributionSetRequestBodyPost}
|
||||
*/
|
||||
public List<DistributionSetRequestBodyPost> build() {
|
||||
return Lists.newArrayList(doBuild(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a list of multiple {@link DistributionSetRequestBodyPost} to
|
||||
* create multiple distribution sets at once. An increasing number will be
|
||||
* added to the name of the distribution set. The version and type will
|
||||
* remain the same.
|
||||
*
|
||||
* @param count
|
||||
* the amount of distribution sets body which should be created
|
||||
* @return a list of {@link DistributionSetRequestBodyPost}
|
||||
*/
|
||||
public List<DistributionSetRequestBodyPost> buildAsList(final int count) {
|
||||
final ArrayList<DistributionSetRequestBodyPost> bodyList = Lists.newArrayList();
|
||||
for (int index = 0; index < count; index++) {
|
||||
bodyList.add(doBuild(name + index));
|
||||
}
|
||||
|
||||
return bodyList;
|
||||
}
|
||||
|
||||
private DistributionSetRequestBodyPost doBuild(final String prefixName) {
|
||||
final DistributionSetRequestBodyPost body = new DistributionSetRequestBodyPost();
|
||||
body.setName(prefixName);
|
||||
body.setVersion(version);
|
||||
body.setType(type);
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client.resource.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRequestBodyPost;
|
||||
import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeAssigmentRest;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
*
|
||||
* Builder pattern for building {@link DistributionSetTypeRequestBodyPost}.
|
||||
*
|
||||
* @author Jonathan Knoblauch
|
||||
*
|
||||
*/
|
||||
public class DistributionSetTypeBuilder {
|
||||
|
||||
private String key;
|
||||
private String name;
|
||||
private final List<SoftwareModuleTypeAssigmentRest> mandatorymodules = Lists.newArrayList();
|
||||
private final List<SoftwareModuleTypeAssigmentRest> optionalmodules = Lists.newArrayList();
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* the key of the distribution set type
|
||||
* @return the builder itself
|
||||
*/
|
||||
public DistributionSetTypeBuilder key(final String key) {
|
||||
this.key = key;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name of the distribution set type
|
||||
* @return the builder itself
|
||||
*/
|
||||
public DistributionSetTypeBuilder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param softwareModuleTypeIds
|
||||
* the IDs of the software module types which should be mandatory
|
||||
* for the distribution set type
|
||||
* @return the builder itself
|
||||
*/
|
||||
public DistributionSetTypeBuilder mandatorymodules(final Long... softwareModuleTypeIds) {
|
||||
for (final Long id : softwareModuleTypeIds) {
|
||||
final SoftwareModuleTypeAssigmentRest softwareModuleTypeAssigmentRest = new SoftwareModuleTypeAssigmentRest();
|
||||
softwareModuleTypeAssigmentRest.setId(id);
|
||||
this.mandatorymodules.add(softwareModuleTypeAssigmentRest);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param softwareModuleTypeIds
|
||||
* the IDs of the software module types which should be optional
|
||||
* for the distribution set type
|
||||
* @return the builder itself
|
||||
*/
|
||||
public DistributionSetTypeBuilder optionalmodules(final Long... softwareModuleTypeIds) {
|
||||
for (final Long id : softwareModuleTypeIds) {
|
||||
final SoftwareModuleTypeAssigmentRest softwareModuleTypeAssigmentRest = new SoftwareModuleTypeAssigmentRest();
|
||||
softwareModuleTypeAssigmentRest.setId(id);
|
||||
this.optionalmodules.add(softwareModuleTypeAssigmentRest);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a list with a single entry of
|
||||
* {@link DistributionSetTypeRequestBodyPost} which can directly be used in
|
||||
* the RESTful-API.
|
||||
*
|
||||
* @return a single entry list of {@link DistributionSetTypeRequestBodyPost}
|
||||
*/
|
||||
public List<DistributionSetTypeRequestBodyPost> build() {
|
||||
return Lists.newArrayList(doBuild(name, key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a list of multiple {@link DistributionSetTypeRequestBodyPost} to
|
||||
* create multiple distribution set types at once. An increasing number will
|
||||
* be added to the name and key of the distribution set type. The optional
|
||||
* and mandatory software module types will remain the same.
|
||||
*
|
||||
* @param count
|
||||
* the amount of distribution sets type body which should be
|
||||
* created
|
||||
* @return a list of {@link DistributionSetTypeRequestBodyPost}
|
||||
*/
|
||||
public List<DistributionSetTypeRequestBodyPost> buildAsList(final int count) {
|
||||
final ArrayList<DistributionSetTypeRequestBodyPost> bodyList = Lists.newArrayList();
|
||||
for (int index = 0; index < count; index++) {
|
||||
bodyList.add(doBuild(name + index, key + index));
|
||||
}
|
||||
return bodyList;
|
||||
|
||||
}
|
||||
|
||||
private DistributionSetTypeRequestBodyPost doBuild(final String prefixName, final String prefixKey) {
|
||||
final DistributionSetTypeRequestBodyPost body = new DistributionSetTypeRequestBodyPost();
|
||||
body.setKey(prefixKey);
|
||||
body.setName(prefixName);
|
||||
body.setMandatorymodules(mandatorymodules);
|
||||
body.setOptionalmodules(optionalmodules);
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client.resource.builder;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.rollout.RolloutCondition;
|
||||
import org.eclipse.hawkbit.rest.resource.model.rollout.RolloutCondition.Condition;
|
||||
import org.eclipse.hawkbit.rest.resource.model.rollout.RolloutRestRequestBody;
|
||||
|
||||
/**
|
||||
*
|
||||
* Builder pattern for building {@link RolloutRestRequestBody}.
|
||||
*
|
||||
* @author Jonathan Knoblauch
|
||||
*
|
||||
*/
|
||||
public class RolloutBuilder {
|
||||
|
||||
private String name;
|
||||
private int groupSize;
|
||||
private String targetFilterQuery;
|
||||
private long distributionSetId;
|
||||
private String successThreshold;
|
||||
private String errorThreshold;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name of the rollout
|
||||
* @return the builder itself
|
||||
*/
|
||||
public RolloutBuilder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param groupSize
|
||||
* the amount of groups the rollout should be split into
|
||||
* @return the builder itself
|
||||
*/
|
||||
public RolloutBuilder groupSize(final int groupSize) {
|
||||
this.groupSize = groupSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param targetFilterQuery
|
||||
* the FIQL query language to filter targets to contain in the
|
||||
* rollout
|
||||
* @return the builder itself
|
||||
*/
|
||||
public RolloutBuilder targetFilterQuery(final String targetFilterQuery) {
|
||||
this.targetFilterQuery = targetFilterQuery;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param distributionSetId
|
||||
* the ID of the distribution set to assign to the target in the
|
||||
* rollout
|
||||
* @return the builder itself
|
||||
*/
|
||||
public RolloutBuilder distributionSetId(final long distributionSetId) {
|
||||
this.distributionSetId = distributionSetId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param successThreshold
|
||||
* the threshold to be used to indicate if a deployment group is
|
||||
* successful, to trigger the success action
|
||||
* @return the builder itself
|
||||
*/
|
||||
public RolloutBuilder successThreshold(final String successThreshold) {
|
||||
this.successThreshold = successThreshold;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param errorThreshold
|
||||
* the threshold to be used to indicate if a deployment group is
|
||||
* failing, to trigger the error action
|
||||
* @return the builder itself
|
||||
*/
|
||||
public RolloutBuilder errorThreshold(final String errorThreshold) {
|
||||
this.errorThreshold = errorThreshold;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the rollout rest body to creating a rollout.
|
||||
*
|
||||
* @return the rest request body for creating a rollout
|
||||
*/
|
||||
public RolloutRestRequestBody build() {
|
||||
return doBuild();
|
||||
}
|
||||
|
||||
private RolloutRestRequestBody doBuild() {
|
||||
final RolloutRestRequestBody body = new RolloutRestRequestBody();
|
||||
body.setName(name);
|
||||
body.setAmountGroups(groupSize);
|
||||
body.setTargetFilterQuery(targetFilterQuery);
|
||||
body.setDistributionSetId(distributionSetId);
|
||||
body.setSuccessCondition(new RolloutCondition(Condition.THRESHOLD, successThreshold));
|
||||
body.setErrorCondition(new RolloutCondition(Condition.THRESHOLD, errorThreshold));
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client.resource.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleAssigmentRest;
|
||||
|
||||
/**
|
||||
*
|
||||
* Builder pattern for building {@link SoftwareModuleAssigmentRest}.
|
||||
*
|
||||
* @author Jonathan Knoblauch
|
||||
*
|
||||
*/
|
||||
public class SoftwareModuleAssigmentBuilder {
|
||||
|
||||
private final List<Long> ids;
|
||||
|
||||
public SoftwareModuleAssigmentBuilder() {
|
||||
ids = new ArrayList<Long>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* the id of the software module
|
||||
* @return the builder itself
|
||||
*/
|
||||
public SoftwareModuleAssigmentBuilder id(final Long id) {
|
||||
ids.add(id);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a list with a single entry of {@link SoftwareModuleAssigmentRest}
|
||||
* which can directly be used in the RESTful-API.
|
||||
*
|
||||
* @return a single entry list of {@link SoftwareModuleAssigmentRest}
|
||||
*/
|
||||
public List<SoftwareModuleAssigmentRest> build() {
|
||||
final List<SoftwareModuleAssigmentRest> softwareModuleAssigmentRestList = new ArrayList<>();
|
||||
for (final Long id : ids) {
|
||||
final SoftwareModuleAssigmentRest softwareModuleAssigmentRest = new SoftwareModuleAssigmentRest();
|
||||
softwareModuleAssigmentRest.setId(id);
|
||||
softwareModuleAssigmentRestList.add(softwareModuleAssigmentRest);
|
||||
}
|
||||
return softwareModuleAssigmentRestList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client.resource.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRequestBodyPost;
|
||||
import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleRequestBodyPost;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
*
|
||||
* Builder pattern for building {@link SoftwareModuleRequestBodyPost}.
|
||||
*
|
||||
* @author Jonathan Knoblauch
|
||||
*
|
||||
*/
|
||||
public class SoftwareModuleBuilder {
|
||||
|
||||
private String name;
|
||||
private String version;
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name of the software module
|
||||
* @return the builder itself
|
||||
*/
|
||||
public SoftwareModuleBuilder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param version
|
||||
* the version of the software module
|
||||
* @return the builder itsefl
|
||||
*/
|
||||
public SoftwareModuleBuilder version(final String version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type
|
||||
* the key of the software module type to be used for this
|
||||
* software module
|
||||
* @return the builder itself
|
||||
*/
|
||||
public SoftwareModuleBuilder type(final String type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a list with a single entry of
|
||||
* {@link SoftwareModuleRequestBodyPost} which can directly be used in the
|
||||
* RESTful-API.
|
||||
*
|
||||
* @return a single entry list of {@link SoftwareModuleRequestBodyPost}
|
||||
*/
|
||||
public List<SoftwareModuleRequestBodyPost> build() {
|
||||
return Lists.newArrayList(doBuild(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a list of multiple {@link SoftwareModuleRequestBodyPost} to create
|
||||
* multiple software module at once. An increasing number will be added to
|
||||
* the name of the software module. The version and type will remain the
|
||||
* same.
|
||||
*
|
||||
* @param count
|
||||
* the amount of software module body which should be created
|
||||
* @return a list of {@link DistributionSetTypeRequestBodyPost}
|
||||
*/
|
||||
public List<SoftwareModuleRequestBodyPost> buildAsList(final int count) {
|
||||
final ArrayList<SoftwareModuleRequestBodyPost> bodyList = Lists.newArrayList();
|
||||
for (int index = 0; index < count; index++) {
|
||||
bodyList.add(doBuild(name + index));
|
||||
}
|
||||
|
||||
return bodyList;
|
||||
}
|
||||
|
||||
private SoftwareModuleRequestBodyPost doBuild(final String prefixName) {
|
||||
final SoftwareModuleRequestBodyPost body = new SoftwareModuleRequestBodyPost();
|
||||
body.setName(prefixName);
|
||||
body.setVersion(version);
|
||||
body.setType(type);
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client.resource.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleRequestBodyPost;
|
||||
import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRequestBodyPost;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
*
|
||||
* Builder pattern for building {@link SoftwareModuleRequestBodyPost}.
|
||||
*
|
||||
* @author Jonathan Knoblauch
|
||||
*
|
||||
*/
|
||||
public class SoftwareModuleTypeBuilder {
|
||||
|
||||
private String key;
|
||||
private String name;
|
||||
private String description;
|
||||
private int maxAssignments;
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* the key of the software module type
|
||||
* @return the builder itself
|
||||
*/
|
||||
public SoftwareModuleTypeBuilder key(final String key) {
|
||||
this.key = key;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name of the software module type
|
||||
* @return the builder itself
|
||||
*/
|
||||
public SoftwareModuleTypeBuilder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SoftwareModuleTypeBuilder description(final String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SoftwareModuleTypeBuilder maxAssignments(final int maxAssignments) {
|
||||
this.maxAssignments = maxAssignments;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a list with a single entry of
|
||||
* {@link SoftwareModuleTypeRequestBodyPost} which can directly be used in
|
||||
* the RESTful-API.
|
||||
*
|
||||
* @return a single entry list of {@link SoftwareModuleTypeRequestBodyPost}
|
||||
*/
|
||||
public List<SoftwareModuleTypeRequestBodyPost> build() {
|
||||
return Lists.newArrayList(doBuild(key, name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a list of multiple {@link SoftwareModuleTypeRequestBodyPost} to
|
||||
* create multiple software module types at once. An increasing number will
|
||||
* be added to the name and key of the software module type.
|
||||
*
|
||||
* @param count
|
||||
* the amount of software module type bodies which should be
|
||||
* created
|
||||
* @return a list of {@link SoftwareModuleTypeRequestBodyPost}
|
||||
*/
|
||||
public List<SoftwareModuleTypeRequestBodyPost> buildAsList(final int count) {
|
||||
final ArrayList<SoftwareModuleTypeRequestBodyPost> bodyList = Lists.newArrayList();
|
||||
for (int index = 0; index < count; index++) {
|
||||
bodyList.add(doBuild(key + index, name + index));
|
||||
}
|
||||
return bodyList;
|
||||
}
|
||||
|
||||
private SoftwareModuleTypeRequestBodyPost doBuild(final String prefixKey, final String prefixName) {
|
||||
final SoftwareModuleTypeRequestBodyPost body = new SoftwareModuleTypeRequestBodyPost();
|
||||
body.setKey(prefixKey);
|
||||
body.setName(prefixName);
|
||||
body.setDescription(description);
|
||||
body.setMaxAssignments(maxAssignments);
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client.resource.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* Builder pattern for building {@link TagRequestBodyPut}.
|
||||
*
|
||||
* @author Jonathan Knoblauch
|
||||
*
|
||||
*/
|
||||
public class TagBuilder {
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
private String color;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name of the tag
|
||||
* @return the builder itself
|
||||
*/
|
||||
public TagBuilder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param description
|
||||
* the description of the tag
|
||||
* @return the builder itself
|
||||
*/
|
||||
public TagBuilder description(final String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param color
|
||||
* the colour of the tag
|
||||
* @return the builder itself
|
||||
*/
|
||||
public TagBuilder color(final String color) {
|
||||
this.color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a list with a single entry of {@link TagRequestBodyPut} which can
|
||||
* directly be used in the RESTful-API.
|
||||
*
|
||||
* @return a single entry list of {@link TagRequestBodyPut}
|
||||
*/
|
||||
public List<TagRequestBodyPut> build() {
|
||||
return Lists.newArrayList(doBuild(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a list of multiple {@link TagRequestBodyPut} to create multiple
|
||||
* tags at once. An increasing number will be added to the name of the tag.
|
||||
* The color and description will remain the same.
|
||||
*
|
||||
* @param count
|
||||
* the amount of distribution sets body which should be created
|
||||
* @return a list of {@link TagRequestBodyPut}
|
||||
*/
|
||||
public List<TagRequestBodyPut> buildAsList(final int count) {
|
||||
final ArrayList<TagRequestBodyPut> bodyList = Lists.newArrayList();
|
||||
for (int index = 0; index < count; index++) {
|
||||
bodyList.add(doBuild(name + index));
|
||||
}
|
||||
|
||||
return bodyList;
|
||||
}
|
||||
|
||||
private TagRequestBodyPut doBuild(final String prefixName) {
|
||||
final TagRequestBodyPut body = new TagRequestBodyPut();
|
||||
body.setName(prefixName);
|
||||
body.setDescription(description);
|
||||
body.setColour(color);
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client.resource.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRequestBodyPost;
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetRequestBody;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
*
|
||||
* Builder pattern for building {@link TargetRequestBody}.
|
||||
*
|
||||
* @author Jonathan Knoblauch
|
||||
*
|
||||
*/
|
||||
public class TargetBuilder {
|
||||
|
||||
private String controllerId;
|
||||
private String name;
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* @param controllerId
|
||||
* the ID of the controller/target
|
||||
* @return the builder itself
|
||||
*/
|
||||
public TargetBuilder controllerId(final String controllerId) {
|
||||
this.controllerId = controllerId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name of the target
|
||||
* @return the builder itself
|
||||
*/
|
||||
public TargetBuilder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param description
|
||||
* the description of the target
|
||||
* @return the builder itself
|
||||
*/
|
||||
public TargetBuilder description(final String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a list with a single entry of {@link TargetRequestBody} which can
|
||||
* directly be used in the RESTful-API.
|
||||
*
|
||||
* @return a single entry list of {@link TargetRequestBody}
|
||||
*/
|
||||
public List<TargetRequestBody> build() {
|
||||
return Lists.newArrayList(doBuild(controllerId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a list of multiple {@link TargetRequestBody} to create multiple
|
||||
* targets at once. An increasing number will be added to the controllerId
|
||||
* of the target. The name and description will remain.
|
||||
*
|
||||
* @param count
|
||||
* the amount of software module type bodies which should be
|
||||
* created
|
||||
* @return a list of {@link SoftwareModuleTypeRequestBodyPost}
|
||||
*/
|
||||
public List<TargetRequestBody> buildAsList(final int count) {
|
||||
final ArrayList<TargetRequestBody> bodyList = Lists.newArrayList();
|
||||
for (int index = 0; index < count; index++) {
|
||||
bodyList.add(doBuild(controllerId + index));
|
||||
}
|
||||
return bodyList;
|
||||
}
|
||||
|
||||
private TargetRequestBody doBuild(final String prefixControllerId) {
|
||||
final TargetRequestBody body = new TargetRequestBody();
|
||||
body.setControllerId(prefixControllerId);
|
||||
body.setName(name);
|
||||
body.setDescription(description);
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.client.scenarios;
|
||||
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.DistributionSetResourceClient;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.DistributionSetTypeResourceClient;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.RolloutResourceClient;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.SoftwareModuleResourceClient;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.SoftwareModuleTypeResourceClient;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.TargetResourceClient;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.builder.DistributionSetBuilder;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.builder.DistributionSetTypeBuilder;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.builder.RolloutBuilder;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleAssigmentBuilder;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleBuilder;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleTypeBuilder;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.builder.TargetBuilder;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.rollout.RolloutResponseBody;
|
||||
import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModulesRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypesRest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Example for creating and starting a Rollout.
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class CreateStartedRolloutExample {
|
||||
|
||||
/* known software module type name and key */
|
||||
private static final String SM_MODULE_TYPE = "firmware";
|
||||
|
||||
/* known distribution set type name and key */
|
||||
private static final String DS_MODULE_TYPE = "firmware";
|
||||
|
||||
@Autowired
|
||||
private DistributionSetResourceClient distributionSetResource;
|
||||
|
||||
@Autowired
|
||||
private SoftwareModuleResourceClient softwareModuleResource;
|
||||
|
||||
@Autowired
|
||||
private TargetResourceClient targetResource;
|
||||
|
||||
@Autowired
|
||||
private RolloutResourceClient rolloutResource;
|
||||
|
||||
@Autowired
|
||||
private DistributionSetTypeResourceClient distributionSetTypeResource;
|
||||
|
||||
@Autowired
|
||||
private SoftwareModuleTypeResourceClient softwareModuleTypeResource;
|
||||
|
||||
/**
|
||||
* Run the Rollout scenario.
|
||||
*/
|
||||
public void run() {
|
||||
|
||||
// create three SoftwareModuleTypes
|
||||
final SoftwareModuleTypesRest createdSoftwareModuleTypes = softwareModuleTypeResource.createSoftwareModuleTypes(
|
||||
new SoftwareModuleTypeBuilder().key(SM_MODULE_TYPE).name(SM_MODULE_TYPE).maxAssignments(1).build())
|
||||
.getBody();
|
||||
|
||||
// create one DistributionSetType
|
||||
distributionSetTypeResource.createDistributionSetTypes(new DistributionSetTypeBuilder().key(DS_MODULE_TYPE)
|
||||
.name(DS_MODULE_TYPE).mandatorymodules(createdSoftwareModuleTypes.get(0).getModuleId()).build())
|
||||
.getBody();
|
||||
|
||||
// create one DistributionSet
|
||||
final DistributionSetsRest distributionSetsRest = distributionSetResource.createDistributionSets(
|
||||
new DistributionSetBuilder().name("rollout-example").version("1.0.0").type(DS_MODULE_TYPE).build())
|
||||
.getBody();
|
||||
|
||||
// create three SoftwareModules
|
||||
final SoftwareModulesRest softwareModulesRest = softwareModuleResource
|
||||
.createSoftwareModules(
|
||||
new SoftwareModuleBuilder().name("firmware").version("1.0.0").type(SM_MODULE_TYPE).build())
|
||||
.getBody();
|
||||
|
||||
// Assign SoftwareModule to DistributionSet
|
||||
distributionSetResource.assignSoftwareModules(distributionSetsRest.get(0).getDsId(),
|
||||
new SoftwareModuleAssigmentBuilder().id(softwareModulesRest.get(0).getModuleId()).build());
|
||||
|
||||
// create ten targets
|
||||
targetResource.createTargets(new TargetBuilder().controllerId("00-FF-AA-0").name("00-FF-AA-0")
|
||||
.description("Targets used for rollout example").buildAsList(10));
|
||||
|
||||
// create a Rollout
|
||||
final RolloutResponseBody rolloutResponseBody = rolloutResource
|
||||
.create(new RolloutBuilder().name("MyRollout").groupSize(2).targetFilterQuery("name==00-FF-AA-0*")
|
||||
.distributionSetId(distributionSetsRest.get(0).getDsId()).successThreshold("80")
|
||||
.errorThreshold("50").build())
|
||||
.getBody();
|
||||
|
||||
// start the created Rollout
|
||||
rolloutResource.start(rolloutResponseBody.getRolloutId(), false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package org.eclipse.hawkbit.mgmt.client.scenarios;
|
||||
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.DistributionSetResourceClient;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.DistributionSetTypeResourceClient;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.SoftwareModuleResourceClient;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.SoftwareModuleTypeResourceClient;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.builder.DistributionSetBuilder;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.builder.DistributionSetTypeBuilder;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleAssigmentBuilder;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleBuilder;
|
||||
import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleTypeBuilder;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModulesRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypesRest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
*
|
||||
* Default getting started scenario.
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class GettingStartedDefaultScenario {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(GettingStartedDefaultScenario.class);
|
||||
|
||||
/* known software module type name and key */
|
||||
private static final String SM_MODULE_TYPE = "gettingstarted";
|
||||
|
||||
/* known distribution set type name and key */
|
||||
private static final String DS_MODULE_TYPE = "gettingstarted";
|
||||
|
||||
/* known distribution name of this getting started example */
|
||||
private static final String SM_EXAMPLE_NAME = "gettingstarted-example";
|
||||
|
||||
/* known distribution name of this getting started example */
|
||||
private static final String DS_EXAMPLE_NAME = "gettingstarted-example";
|
||||
|
||||
@Autowired
|
||||
private DistributionSetResourceClient distributionSetResource;
|
||||
|
||||
@Autowired
|
||||
private DistributionSetTypeResourceClient distributionSetTypeResource;
|
||||
|
||||
@Autowired
|
||||
private SoftwareModuleResourceClient softwareModuleResource;
|
||||
|
||||
@Autowired
|
||||
private SoftwareModuleTypeResourceClient softwareModuleTypeResource;
|
||||
|
||||
/**
|
||||
* Run the default getting started scenario.
|
||||
*/
|
||||
public void run() {
|
||||
|
||||
LOGGER.info("Running Getting-Started-Scenario...");
|
||||
|
||||
// create one SoftwareModuleTypes
|
||||
LOGGER.info("Creating software module type {}", SM_MODULE_TYPE);
|
||||
final SoftwareModuleTypesRest createdSoftwareModuleTypes = softwareModuleTypeResource.createSoftwareModuleTypes(
|
||||
new SoftwareModuleTypeBuilder().key(SM_MODULE_TYPE).name(SM_MODULE_TYPE).maxAssignments(1).build())
|
||||
.getBody();
|
||||
|
||||
// create one DistributionSetType
|
||||
LOGGER.info("Creating distribution set type {}", DS_MODULE_TYPE);
|
||||
distributionSetTypeResource.createDistributionSetTypes(new DistributionSetTypeBuilder().key(DS_MODULE_TYPE)
|
||||
.name(DS_MODULE_TYPE).mandatorymodules(createdSoftwareModuleTypes.get(0).getModuleId()).build());
|
||||
|
||||
// create three DistributionSet
|
||||
final String dsVersion1 = "1.0.0";
|
||||
final String dsVersion2 = "2.0.0";
|
||||
final String dsVersion3 = "2.1.0";
|
||||
|
||||
LOGGER.info("Creating distribution set {}:{}", DS_EXAMPLE_NAME, dsVersion1);
|
||||
final DistributionSetsRest distributionSetsRest1 = distributionSetResource.createDistributionSets(
|
||||
new DistributionSetBuilder().name(DS_EXAMPLE_NAME).version(dsVersion1).type(DS_MODULE_TYPE).build())
|
||||
.getBody();
|
||||
|
||||
LOGGER.info("Creating distribution set {}:{}", DS_EXAMPLE_NAME, dsVersion2);
|
||||
final DistributionSetsRest distributionSetsRest2 = distributionSetResource.createDistributionSets(
|
||||
new DistributionSetBuilder().name(DS_EXAMPLE_NAME).version(dsVersion2).type(DS_MODULE_TYPE).build())
|
||||
.getBody();
|
||||
|
||||
LOGGER.info("Creating distribution set {}:{}", DS_EXAMPLE_NAME, dsVersion3);
|
||||
final DistributionSetsRest distributionSetsRest3 = distributionSetResource.createDistributionSets(
|
||||
new DistributionSetBuilder().name(DS_EXAMPLE_NAME).version(dsVersion3).type(DS_MODULE_TYPE).build())
|
||||
.getBody();
|
||||
|
||||
// create three SoftwareModules
|
||||
final String swVersion1 = "1";
|
||||
final String swVersion2 = "2";
|
||||
final String swVersion3 = "3";
|
||||
|
||||
LOGGER.info("Creating distribution set {}:{}", SM_EXAMPLE_NAME, swVersion1);
|
||||
final SoftwareModulesRest softwareModulesRest1 = softwareModuleResource.createSoftwareModules(
|
||||
new SoftwareModuleBuilder().name(SM_EXAMPLE_NAME).version(swVersion1).type(SM_MODULE_TYPE).build())
|
||||
.getBody();
|
||||
LOGGER.info("Creating distribution set {}:{}", SM_EXAMPLE_NAME, swVersion2);
|
||||
final SoftwareModulesRest softwareModulesRest2 = softwareModuleResource.createSoftwareModules(
|
||||
new SoftwareModuleBuilder().name(SM_EXAMPLE_NAME).version(swVersion2).type(SM_MODULE_TYPE).build())
|
||||
.getBody();
|
||||
LOGGER.info("Creating distribution set {}:{}", SM_EXAMPLE_NAME, swVersion3);
|
||||
final SoftwareModulesRest softwareModulesRest3 = softwareModuleResource.createSoftwareModules(
|
||||
new SoftwareModuleBuilder().name(SM_EXAMPLE_NAME).version(swVersion3).type(SM_MODULE_TYPE).build())
|
||||
.getBody();
|
||||
|
||||
// Assign SoftwareModules to DistributionSet
|
||||
LOGGER.info("Assign software module {}:{} to distribution set {}:{}", SM_EXAMPLE_NAME, swVersion1,
|
||||
DS_EXAMPLE_NAME, dsVersion1);
|
||||
distributionSetResource.assignSoftwareModules(distributionSetsRest1.get(0).getDsId(),
|
||||
new SoftwareModuleAssigmentBuilder().id(softwareModulesRest1.get(0).getModuleId()).build());
|
||||
|
||||
LOGGER.info("Assign software module {}:{} to distribution set {}:{}", SM_EXAMPLE_NAME, swVersion2,
|
||||
DS_EXAMPLE_NAME, dsVersion2);
|
||||
distributionSetResource.assignSoftwareModules(distributionSetsRest2.get(0).getDsId(),
|
||||
new SoftwareModuleAssigmentBuilder().id(softwareModulesRest2.get(0).getModuleId()).build());
|
||||
|
||||
LOGGER.info("Assign software module {}:{} to distribution set {}:{}", SM_EXAMPLE_NAME, swVersion3,
|
||||
DS_EXAMPLE_NAME, dsVersion3);
|
||||
distributionSetResource.assignSoftwareModules(distributionSetsRest3.get(0).getDsId(),
|
||||
new SoftwareModuleAssigmentBuilder().id(softwareModulesRest3.get(0).getModuleId()).build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
logging.level=trace
|
||||
hawkbit.url=localhost:8080
|
||||
hawkbit.username=admin
|
||||
hawkbit.password=admin
|
||||
|
||||
spring.main.banner-mode=OFF
|
||||
@@ -0,0 +1,20 @@
|
||||
<!-- Copyright (c) 2015 Bosch Software Innovations GmbH and others. All rights reserved. This program and the accompanying
|
||||
materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and
|
||||
is available at http://www.eclipse.org/legal/epl-v10.html -->
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<!-- Log message format -->
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="org.eclipse.hawkbit" level="info" />
|
||||
|
||||
<root level="error">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
@@ -1,186 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.api.client;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.app.Start;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRequestBodyPost;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.AssignedDistributionSetRequestBody;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.DistributionSetTagAssigmentResultRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.context.annotation.Description;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
import feign.Feign;
|
||||
import feign.Logger;
|
||||
import feign.auth.BasicAuthRequestInterceptor;
|
||||
import feign.jackson.JacksonDecoder;
|
||||
import feign.jackson.JacksonEncoder;
|
||||
|
||||
@Features("Example Tests - Management RESTful API Client")
|
||||
@Stories("DistrubutionSet Tag Resource")
|
||||
public class DistributionSetTagTest {
|
||||
|
||||
private DistrubutionSetTagResource distrubutionSetTagResource;
|
||||
|
||||
private static List<AssignedDistributionSetRequestBody> assignedTargetRequestBodies;
|
||||
|
||||
@BeforeClass
|
||||
public static void startupServer() {
|
||||
SpringApplication.run(Start.class, new String[0]);
|
||||
createTargetsAssignment();
|
||||
assignedTargetRequestBodies.add(new AssignedDistributionSetRequestBody().setDistributionSetId(100L));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.distrubutionSetTagResource = createDistrubutionSetTagResource();
|
||||
}
|
||||
|
||||
// disabled as this runs not on CI environments.
|
||||
@Test
|
||||
@Description("Simple request of distrubutionset tag by ID")
|
||||
@Ignore
|
||||
public void getDistributionSetTag() {
|
||||
final TagsRest result = createDistributionSetTags(2);
|
||||
|
||||
assertThat(distrubutionSetTagResource.getDistributionSetTag(result.get(0).getTagId()).getName()).isEqualTo(
|
||||
"Tag0");
|
||||
|
||||
deleteDistributionSets(result);
|
||||
}
|
||||
|
||||
// disabled as this runs not on CI environments.
|
||||
@Test
|
||||
@Description("Simple update of a distrubutionset tag")
|
||||
@Ignore
|
||||
public void updateDistributionSetTag() {
|
||||
final TagsRest created = createDistributionSetTags(10);
|
||||
|
||||
distrubutionSetTagResource.updateDistributionSetTag(created.get(0).getTagId(), new TagRequestBodyPut()
|
||||
.setDescription("Test").setName("Test").setColour("Green"));
|
||||
|
||||
final TagRest targetTag = distrubutionSetTagResource.getDistributionSetTag(created.get(0).getTagId());
|
||||
assertThat(targetTag.getName()).isEqualTo("Test");
|
||||
assertThat(targetTag.getDescription()).isEqualTo("Test");
|
||||
assertThat(targetTag.getColour()).isEqualTo("Green");
|
||||
|
||||
deleteDistributionSets(created);
|
||||
}
|
||||
|
||||
// disabled as this runs not on CI environments.
|
||||
@Test
|
||||
@Description("Simple request of all assigned distrubutionsets by a distrubutionset tag.")
|
||||
@Ignore
|
||||
public void getDistributionSetByTagId() {
|
||||
final TagsRest created = createDistributionSetTags(10);
|
||||
distrubutionSetTagResource.assignDistributionSets(created.get(2).getTagId(), assignedTargetRequestBodies);
|
||||
|
||||
final DistributionSetsRest distributionSetsRest = distrubutionSetTagResource
|
||||
.getAssignedDistributionSets(created.get(2).getTagId());
|
||||
assertThat(distributionSetsRest).hasSize(5);
|
||||
|
||||
distrubutionSetTagResource.unassignDistributionSets(created.get(2).getTagId());
|
||||
deleteDistributionSets(created);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Toggle request to unassigned all assigned distrubutionset and assign all unassigned distrubutionset.")
|
||||
@Ignore
|
||||
public void toggleTagAssignment() {
|
||||
final TagsRest created = createDistributionSetTags(10);
|
||||
final Long id = created.get(2).getTagId();
|
||||
|
||||
distrubutionSetTagResource.assignDistributionSets(id, assignedTargetRequestBodies);
|
||||
distrubutionSetTagResource.unassignDistributionSet(id, assignedTargetRequestBodies.get(0)
|
||||
.getDistributionSetId());
|
||||
|
||||
DistributionSetTagAssigmentResultRest assigmentResultRest = distrubutionSetTagResource.toggleTagAssignment(id,
|
||||
assignedTargetRequestBodies);
|
||||
|
||||
final TagRest targetTag = distrubutionSetTagResource.getDistributionSetTag(created.get(2).getTagId());
|
||||
assertThat(assigmentResultRest.getAssignedDistributionSets()).hasSize(1);
|
||||
assertThat(assigmentResultRest.getUnassignedDistributionSets()).hasSize(0);
|
||||
|
||||
assigmentResultRest = distrubutionSetTagResource.toggleTagAssignment(id, assignedTargetRequestBodies);
|
||||
assertThat(assigmentResultRest.getAssignedDistributionSets()).hasSize(0);
|
||||
assertThat(assigmentResultRest.getUnassignedDistributionSets()).hasSize(5);
|
||||
|
||||
distrubutionSetTagResource.unassignDistributionSets(targetTag.getTagId());
|
||||
deleteDistributionSets(created);
|
||||
}
|
||||
|
||||
private void deleteDistributionSets(final List<TagRest> tags) {
|
||||
for (final TagRest tag : tags) {
|
||||
distrubutionSetTagResource.deleteDistributionSetTag(tag.getTagId());
|
||||
}
|
||||
}
|
||||
|
||||
private TagsRest createDistributionSetTags(final int number) {
|
||||
|
||||
final List<TagRequestBodyPut> tags = new ArrayList<>();
|
||||
for (int i = 0; i < number; i++) {
|
||||
tags.add(new TagRequestBodyPut().setDescription("Tag " + i).setName("Tag" + i).setColour("Red"));
|
||||
}
|
||||
|
||||
final TagsRest result = distrubutionSetTagResource.createDistributionSetTags(tags);
|
||||
|
||||
assertThat(result).hasSize(number);
|
||||
return result;
|
||||
}
|
||||
|
||||
private DistrubutionSetTagResource createDistrubutionSetTagResource() {
|
||||
final DistrubutionSetTagResource distrubutionSetTagResource = Feign.builder().logger(new Logger.ErrorLogger())
|
||||
.logLevel(Logger.Level.BASIC).decoder(new JacksonDecoder()).encoder(new JacksonEncoder())
|
||||
.requestInterceptor(new BasicAuthRequestInterceptor("admin", "admin"))
|
||||
.target(DistrubutionSetTagResource.class, "http://localhost:8080");
|
||||
return distrubutionSetTagResource;
|
||||
}
|
||||
|
||||
private static void createTargetsAssignment() {
|
||||
|
||||
final List<DistributionSetRequestBodyPost> sets = new ArrayList<>();
|
||||
assignedTargetRequestBodies = new ArrayList<>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
final DistributionSetRequestBodyPost bodyPost = (DistributionSetRequestBodyPost) new DistributionSetRequestBodyPost()
|
||||
.setName("Ds" + i).setDescription("Ds" + i).setVersion("" + i);
|
||||
sets.add(bodyPost);
|
||||
}
|
||||
|
||||
final DistributionSetsRest result = createDistributionSetResource().createDistributionSets(sets);
|
||||
for (final DistributionSetRest rest : result) {
|
||||
assignedTargetRequestBodies.add(new AssignedDistributionSetRequestBody().setDistributionSetId(rest
|
||||
.getDsId()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static DistributionSetResource createDistributionSetResource() {
|
||||
final DistributionSetResource distributionSetResource = Feign.builder().logger(new Logger.ErrorLogger())
|
||||
.logLevel(Logger.Level.BASIC).decoder(new JacksonDecoder()).encoder(new JacksonEncoder())
|
||||
.requestInterceptor(new BasicAuthRequestInterceptor("admin", "admin"))
|
||||
.target(DistributionSetResource.class, "http://localhost:8080");
|
||||
return distributionSetResource;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,182 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.api.client;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.app.Start;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.AssignedTargetRequestBody;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TargetTagAssigmentResultRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetRequestBody;
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetsRest;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.context.annotation.Description;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
import feign.Feign;
|
||||
import feign.Logger;
|
||||
import feign.auth.BasicAuthRequestInterceptor;
|
||||
import feign.jackson.JacksonDecoder;
|
||||
import feign.jackson.JacksonEncoder;
|
||||
|
||||
@Features("Example Tests - Management RESTful API Client")
|
||||
@Stories("Target Tag Resource")
|
||||
public class TargetTagTest {
|
||||
|
||||
private TargetTagResource targetTagResource;
|
||||
|
||||
private static List<AssignedTargetRequestBody> assignedTargetRequestBodies;
|
||||
|
||||
@BeforeClass
|
||||
public static void startupServer() {
|
||||
SpringApplication.run(Start.class, new String[0]);
|
||||
createTargetsAssignment();
|
||||
assignedTargetRequestBodies.add(new AssignedTargetRequestBody().setControllerId("NotExist"));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.targetTagResource = createTargetTagResource();
|
||||
}
|
||||
|
||||
// disabled as this runs not on CI environments.
|
||||
@Test
|
||||
@Description("Simple request of target tag by ID")
|
||||
@Ignore
|
||||
public void getTargetTag() {
|
||||
final TagsRest result = createTargetTags(2);
|
||||
|
||||
assertThat(targetTagResource.getTargetTag(result.get(0).getTagId()).getName()).isEqualTo("Tag0");
|
||||
|
||||
deleteTargets(result);
|
||||
}
|
||||
|
||||
// disabled as this runs not on CI environments.
|
||||
@Test
|
||||
@Description("Simple update of a target tag")
|
||||
@Ignore
|
||||
public void updateTargetTag() {
|
||||
final TagsRest created = createTargetTags(10);
|
||||
|
||||
targetTagResource.updateTagretTag(created.get(0).getTagId(), new TagRequestBodyPut().setDescription("Test")
|
||||
.setName("Test").setColour("Green"));
|
||||
|
||||
final TagRest targetTag = targetTagResource.getTargetTag(created.get(0).getTagId());
|
||||
assertThat(targetTag.getName()).isEqualTo("Test");
|
||||
assertThat(targetTag.getDescription()).isEqualTo("Test");
|
||||
assertThat(targetTag.getColour()).isEqualTo("Green");
|
||||
|
||||
deleteTargets(created);
|
||||
}
|
||||
|
||||
// disabled as this runs not on CI environments.
|
||||
@Test
|
||||
@Description("Simple request of all assigned targets by a target tag.")
|
||||
@Ignore
|
||||
public void getTargetsByTargetTagId() {
|
||||
final TagsRest created = createTargetTags(10);
|
||||
final Long tagId = created.get(2).getTagId();
|
||||
targetTagResource.assignTargets(tagId, assignedTargetRequestBodies);
|
||||
|
||||
final TagRest targetTag = targetTagResource.getTargetTag(tagId);
|
||||
assertThat(targetTagResource.getAssignedTargets(tagId)).hasSize(5);
|
||||
|
||||
targetTagResource.unassignTargets(targetTag.getTagId());
|
||||
deleteTargets(created);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Toggle request to unassigned all assigned targets and assign all unassigned targets.")
|
||||
@Ignore
|
||||
public void toggleTagAssignment() {
|
||||
final TagsRest created = createTargetTags(10);
|
||||
final Long id = created.get(2).getTagId();
|
||||
|
||||
targetTagResource.assignTargets(id, assignedTargetRequestBodies);
|
||||
targetTagResource.unassignTarget(id, assignedTargetRequestBodies.get(0).getControllerId());
|
||||
|
||||
TargetTagAssigmentResultRest assigmentResultRest = targetTagResource.toggleTagAssignment(id,
|
||||
assignedTargetRequestBodies);
|
||||
|
||||
final TagRest targetTag = targetTagResource.getTargetTag(created.get(2).getTagId());
|
||||
assertThat(assigmentResultRest.getAssignedTargets()).hasSize(1);
|
||||
assertThat(assigmentResultRest.getUnassignedTargets()).hasSize(0);
|
||||
|
||||
assigmentResultRest = targetTagResource.toggleTagAssignment(id, assignedTargetRequestBodies);
|
||||
assertThat(assigmentResultRest.getAssignedTargets()).hasSize(0);
|
||||
assertThat(assigmentResultRest.getUnassignedTargets()).hasSize(5);
|
||||
|
||||
targetTagResource.unassignTargets(targetTag.getTagId());
|
||||
deleteTargets(created);
|
||||
}
|
||||
|
||||
private void deleteTargets(final List<TagRest> tags) {
|
||||
for (final TagRest tag : tags) {
|
||||
targetTagResource.deleteTargetTag(tag.getTagId());
|
||||
}
|
||||
}
|
||||
|
||||
private TagsRest createTargetTags(final int number) {
|
||||
|
||||
final List<TagRequestBodyPut> tags = new ArrayList<>();
|
||||
for (int i = 0; i < number; i++) {
|
||||
tags.add(new TagRequestBodyPut().setDescription("Tag " + i).setName("Tag" + i).setColour("Red"));
|
||||
}
|
||||
|
||||
final TagsRest result = targetTagResource.createTargetTag(tags);
|
||||
|
||||
assertThat(result).hasSize(number);
|
||||
return result;
|
||||
}
|
||||
|
||||
private TargetTagResource createTargetTagResource() {
|
||||
final TargetTagResource targetResource = Feign.builder().logger(new Logger.ErrorLogger())
|
||||
.logLevel(Logger.Level.BASIC).decoder(new JacksonDecoder()).encoder(new JacksonEncoder())
|
||||
.requestInterceptor(new BasicAuthRequestInterceptor("admin", "admin"))
|
||||
.target(TargetTagResource.class, "http://localhost:8080");
|
||||
return targetResource;
|
||||
}
|
||||
|
||||
private static void createTargetsAssignment() {
|
||||
|
||||
final List<TargetRequestBody> targets = new ArrayList<>();
|
||||
assignedTargetRequestBodies = new ArrayList<>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
|
||||
targets.add(new TargetRequestBody().setControllerId("test" + i).setName("testDevice"));
|
||||
}
|
||||
|
||||
final TargetsRest result = createTargetResource().createTargets(targets);
|
||||
for (final TargetRest rest : result) {
|
||||
assignedTargetRequestBodies.add(new AssignedTargetRequestBody().setControllerId(rest.getControllerId()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static TargetResource createTargetResource() {
|
||||
final TargetResource targetResource = Feign.builder().logger(new Logger.ErrorLogger())
|
||||
.logLevel(Logger.Level.BASIC).decoder(new JacksonDecoder()).encoder(new JacksonEncoder())
|
||||
.requestInterceptor(new BasicAuthRequestInterceptor("admin", "admin"))
|
||||
.target(TargetResource.class, "http://localhost:8080");
|
||||
return targetResource;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.api.client;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.app.Start;
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetPagedList;
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetRequestBody;
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetsRest;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.context.annotation.Description;
|
||||
|
||||
import feign.Feign;
|
||||
import feign.Logger;
|
||||
import feign.auth.BasicAuthRequestInterceptor;
|
||||
import feign.jackson.JacksonDecoder;
|
||||
import feign.jackson.JacksonEncoder;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Example Tests - Management RESTful API Client")
|
||||
@Stories("Target Resource")
|
||||
public class TargetTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void startupServer() {
|
||||
SpringApplication.run(Start.class, new String[0]);
|
||||
}
|
||||
|
||||
// disabled as this runs not on CI environments.
|
||||
@Test
|
||||
@Description("Simple request of target by ID")
|
||||
@Ignore
|
||||
public void getTarget() {
|
||||
final TargetResource targetResource = createTargetResource();
|
||||
final TargetsRest result = createTargets(targetResource, 1);
|
||||
|
||||
assertThat(targetResource.getTarget("test0").getName()).isEqualTo("testDevice");
|
||||
|
||||
deleteTargets(targetResource, result);
|
||||
}
|
||||
|
||||
// disabled as this runs not on CI environments.
|
||||
@Test
|
||||
@Description("Simple request of all targets with defined page sizing information (i.e. offset and limit).")
|
||||
@Ignore
|
||||
public void getTargetsAsPagedListWithDefinedPageSizing() {
|
||||
final TargetResource targetResource = createTargetResource();
|
||||
final TargetsRest created = createTargets(targetResource, 20);
|
||||
|
||||
final TargetPagedList queryResult = targetResource.getTargets(0, 10);
|
||||
|
||||
assertThat(queryResult.getContent()).hasSize(10);
|
||||
assertThat(queryResult.getTotal()).isEqualTo(20);
|
||||
assertThat(queryResult.getSize()).isEqualTo(10);
|
||||
|
||||
deleteTargets(targetResource, created);
|
||||
}
|
||||
|
||||
// disabled as this runs not on CI environments.
|
||||
@Test
|
||||
@Description("Simple request of all targets with defualt paging parameters.")
|
||||
@Ignore
|
||||
public void getTargetsAsPagedListWithDefaultPageSizing() {
|
||||
final TargetResource targetResource = createTargetResource();
|
||||
final TargetsRest created = createTargets(targetResource, 20);
|
||||
|
||||
final TargetPagedList queryResult = targetResource.getTargets();
|
||||
|
||||
assertThat(queryResult.getContent()).hasSize(20);
|
||||
assertThat(queryResult.getTotal()).isEqualTo(20);
|
||||
assertThat(queryResult.getSize()).isEqualTo(20);
|
||||
|
||||
deleteTargets(targetResource, created);
|
||||
}
|
||||
|
||||
private void deleteTargets(final TargetResource targetResource, final List<TargetRest> targets) {
|
||||
for (final TargetRest targetRest : targets) {
|
||||
targetResource.deleteTarget(targetRest.getControllerId());
|
||||
}
|
||||
}
|
||||
|
||||
private TargetsRest createTargets(final TargetResource targetResource, final int number) {
|
||||
|
||||
final List<TargetRequestBody> targets = new ArrayList<>();
|
||||
for (int i = 0; i < number; i++) {
|
||||
|
||||
targets.add(new TargetRequestBody().setControllerId("test" + i).setName("testDevice"));
|
||||
}
|
||||
|
||||
final TargetsRest result = targetResource.createTargets(targets);
|
||||
|
||||
assertThat(result).hasSize(number);
|
||||
return result;
|
||||
}
|
||||
|
||||
private TargetResource createTargetResource() {
|
||||
final TargetResource targetResource = Feign.builder().logger(new Logger.ErrorLogger())
|
||||
.logLevel(Logger.Level.BASIC).decoder(new JacksonDecoder()).encoder(new JacksonEncoder())
|
||||
.requestInterceptor(new BasicAuthRequestInterceptor("admin", "admin"))
|
||||
.target(TargetResource.class, "http://localhost:8080");
|
||||
return targetResource;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user