Initial check in accordance with Parallel IP

This commit is contained in:
Kai Zimmermann
2016-01-21 13:18:55 +01:00
parent c5e4f1139f
commit 7497ab61ed
763 changed files with 114508 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
/**
* 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;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Defines the polling time for the controllers in HH:MM:SS notation.
*
*
*
*/
@ConfigurationProperties(prefix = "hawkbit.controller")
public class ControllerPollProperties {
private String pollingTime = "00:05:00";
private String pollingOverdueTime = "00:05:00";
public String getPollingTime() {
return pollingTime;
}
public void setPollingTime(final String pollingTime) {
this.pollingTime = pollingTime;
}
public String getPollingOverdueTime() {
return pollingOverdueTime;
}
public void setPollingOverdueTime(final String pollingOverdue) {
this.pollingOverdueTime = pollingOverdue;
}
}

View File

@@ -0,0 +1,78 @@
/**
* 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;
import java.io.IOException;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.ResourcePatternResolver;
/**
* This resource bundles using specified basenames, to resource loading. This
* MessageSource implementation supports more than 1 properties file with the
* same name. All properties files will be merged.
*
*
*
*/
public class DistributedResourceBundleMessageSource extends ReloadableResourceBundleMessageSource {
private static final Logger LOGGER = LoggerFactory.getLogger(DistributedResourceBundleMessageSource.class);
private static final String PROPERTIES_SUFFIX = ".properties";
private ResourceLoader resourceLoader;
/**
* Constructor to set Defaults. Default base name is classpath*:/messages.
* So all messages_ will be found.
*/
public DistributedResourceBundleMessageSource() {
setBasename("classpath*:/messages");
setDefaultEncoding("UTF-8");
setUseCodeAsDefaultMessage(true);
}
@Override
protected PropertiesHolder refreshProperties(final String filename, final PropertiesHolder propHolder) {
final Properties properties = new Properties();
long lastModified = -1;
if (!(resourceLoader instanceof ResourcePatternResolver)) {
LOGGER.warn(
"Resource Loader {} doensn't support getting multiple resources. Default properties mechanism will used",
resourceLoader.getClass().getName());
return super.refreshProperties(filename, propHolder);
}
try {
final Resource[] resources = ((ResourcePatternResolver) resourceLoader)
.getResources(filename + PROPERTIES_SUFFIX);
for (final Resource resource : resources) {
final String sourcePath = resource.getURI().toString().replace(PROPERTIES_SUFFIX, "");
final PropertiesHolder holder = super.refreshProperties(sourcePath, propHolder);
properties.putAll(holder.getProperties());
if (lastModified < resource.lastModified()) {
lastModified = resource.lastModified();
}
}
} catch (final IOException ignored) {
LOGGER.warn("Resource with filname " + filename + " couldn't load", ignored);
}
return new PropertiesHolder(properties, lastModified);
}
@Override
public void setResourceLoader(final ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
super.setResourceLoader(resourceLoader);
}
}

View File

@@ -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.api;
import java.net.URL;
/**
* Resolve to reach the server url.
*
*
*
*/
public interface HostnameResolver {
/**
*
*
* @return
*/
URL resolveHostname();
}

View File

@@ -0,0 +1,109 @@
/**
* 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.artifact.repository;
import java.io.InputStream;
import java.util.List;
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash;
/**
* ArtifactRepository service interface.
*
*
*
*/
public interface ArtifactRepository {
/**
* Stores an artifact into the repository.
*
* @param tenant
* the tenant to store the artifact
* @param content
* the content to store
* @param filename
* the filename of the artifact
* @param contentType
* the content type of the artifact
* @return the stored artifact
* @throws ArtifactStoreException
* in case storing of the artifact was not successful
*/
DbArtifact store(final InputStream content, final String filename, final String contentType);
/**
* Stores an artifact into the repository.
*
* @param content
* the content to store
* @param filename
* the filename of the artifact
* @param contentType
* the content type of the artifact
* @param hash
* the hashes of the artifact to do hash-checks after storing the
* artifact, might be {@code null}
* @return the stored artifact
* @throws ArtifactStoreException
* in case storing of the artifact was not successful
* @throws HashNotMatchException
* in case {@code hash} is provided and not matching to the
* calculated hashes during storing
*/
DbArtifact store(final InputStream content, final String filename, final String contentType, DbArtifactHash hash);
/**
* Deletes an artifact by its ID.
*
* @param artifactId
* the ID of the artifact to delete
*/
void deleteById(final String artifactId);
/**
* Deletes an artifact by its SHA1 hash.
*
* @param sha1Hash
* the sha1-hash of the artifact to delete
*/
void deleteBySha1(final String sha1Hash);
/**
* Retrieves a {@link DbArtifact} from the store by it's SHA1 hash.
*
* @param sha1Hash
* the sha1-hash of the file to lookup.
* @return The artifact file object or {@code null} if no file exists.
*/
DbArtifact getArtifactBySha1(String sha1);
/**
* Retrieves a {@link DbArtifact} from the store by it's ID.
*
* @param id
* the ID of the artifact to retrieve
* @return The artifact file object or {@code null} if no file exists.
*/
DbArtifact getArtifactById(final String id);
/**
* Retrieves a list of {@link GridFSDBFile} from the store by all SHA1
* hashes.
*
* @param tenant
* the tenant to retrieve the artifacts from, ignore case.
* @param sha1Hashes
* the sha1-hashes of the files to lookup.
* @return list of artfiacts
*/
List<DbArtifact> getArtifactsBySha1(final List<String> sha1Hashes);
}

View File

@@ -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.artifact.repository;
/**
* {@link ArtifactStoreException} is thrown in case storing of an artifact was
* not successful.
*
*
*
*/
public class ArtifactStoreException extends RuntimeException {
private static final long serialVersionUID = 1L;
/**
* Constructs a ArtifactStoreException with message and cause.
*
* @param message
* the message of the exception
* @param cause
* the cause of the exception
*/
public ArtifactStoreException(final String message, final Throwable cause) {
super(message, cause);
}
/**
* Constructs a ArtifactStoreException with message.
*
* @param message
* the message of the exception
*/
public ArtifactStoreException(final String message) {
super(message);
}
}

View File

@@ -0,0 +1,61 @@
/**
* 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.artifact.repository;
/**
* Thrown when provided hashes and hashes caluclated during storing are not
* matching.
*
*
*
*/
public class HashNotMatchException extends RuntimeException {
private static final long serialVersionUID = 1L;
public static final String SHA1 = "SHA-1";
public static final String MD5 = "MD5";
private final String hashFunction;
/**
* Constructs a HashNotMatchException with message and cause.
*
* @param message
* the message of the exception
* @param cause
* the cause of the exception
* @param hashFunction
* the hash function which caused this exception
*/
public HashNotMatchException(final String message, final Throwable cause, final String hashFunction) {
super(message, cause);
this.hashFunction = hashFunction;
}
/**
* Constructs a HashNotMatchException with message.
*
* @param message
* the message of the exception
* @param hashFunction
* the hash function which caused this exception
*/
public HashNotMatchException(final String message, final String hashFunction) {
super(message);
this.hashFunction = hashFunction;
}
/**
* @return the hashFunction
*/
public String getHashFunction() {
return hashFunction;
}
}

View File

@@ -0,0 +1,82 @@
/**
* 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.artifact.repository.model;
import java.io.InputStream;
import java.io.OutputStream;
/**
* Database representation of artifact.
*
*
*
*
*/
public class DbArtifact {
private String artifactId;
private DbArtifactHash hashes;
private Long size;
private String contentType;
private InputStream fileInputStream;
private OutputStream fileOutputStream;
public void setArtifactId(final String artifactId) {
this.artifactId = artifactId;
}
public String getArtifactId() {
return artifactId;
}
public DbArtifactHash getHashes() {
return hashes;
}
public void setHashes(final DbArtifactHash hashes) {
this.hashes = hashes;
}
public Long getSize() {
return size;
}
public void setSize(final Long size) {
this.size = size;
}
public void setContentType(final String contentType) {
this.contentType = contentType;
}
public String getContentType() {
return contentType;
}
public void setFileInputStream(final InputStream fileInputStream) {
this.fileInputStream = fileInputStream;
}
public InputStream getFileInputStream() {
return fileInputStream;
}
public OutputStream getFileOutputStream() {
return fileOutputStream;
}
public void setFileOutputStream(final OutputStream fileOutputStream) {
this.fileOutputStream = fileOutputStream;
}
}

View File

@@ -0,0 +1,54 @@
/**
* 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.artifact.repository.model;
/**
* Database representation of artifact hash.
*
*
*
*
*/
public class DbArtifactHash {
private String sha1;
private String md5;
/**
* Constructor.
*
* @param sha1
* the sha1 hash
* @param md5
* the md5 hash
*/
public DbArtifactHash(final String sha1, final String md5) {
super();
this.sha1 = sha1;
this.md5 = md5;
}
public void setSha1(final String sha1) {
this.sha1 = sha1;
}
public void setMd5(final String md5) {
this.md5 = md5;
}
public String getSha1() {
return sha1;
}
public String getMd5() {
return md5;
}
}

View File

@@ -0,0 +1,27 @@
/**
* 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.cache;
/**
* Cache Constants.
*
*
*
*/
public final class CacheConstants {
/**
* Constant for download cache id.
*/
public static final String DOWNLOAD_ID_CACHE = "DowonloadIdCache";
private CacheConstants() {
}
}

View File

@@ -0,0 +1,44 @@
/**
* 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.cache;
/**
* Cache Object for download a Artifact.
*
*
*
*/
public class DownloadArtifactCache {
private final DownloadType downloadType;
private final String id;
/**
* Constructor.
*
* @param downloadType
* the type for searching the artifact.
* @param id
* the searching id e.g. sha1, md5
*/
public DownloadArtifactCache(final DownloadType downloadType, final String id) {
super();
this.downloadType = downloadType;
this.id = id;
}
public String getId() {
return id;
}
public DownloadType getDownloadType() {
return downloadType;
}
}

View File

@@ -0,0 +1,19 @@
/**
* 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.cache;
/**
* The type of the id which is saved.
*
*
*
*/
public enum DownloadType {
BY_SHA1
}

View File

@@ -0,0 +1,40 @@
/**
* 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.cache;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
/**
*
*
*/
public interface TenancyCacheManager extends CacheManager {
/**
* A direct access for retrieving the cache without including the current
* tenant key. This is necessary e.g. for retrieving caches not for the
* current tenant.
*
* @param name
* the name of the cache to retrieve directly
* @return the cache associated with the name without tenancy separation
*/
Cache getDirectCache(String name);
/**
* Evicts all caches for a given tenant. All caches under a certain tenant
* gets evicted.
*
* @param tenant
* the tenant to evict caches
*/
void evictCaches(final String tenant);
}

View File

@@ -0,0 +1,102 @@
/**
* 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.cache;
import java.util.Collection;
import java.util.Collections;
import java.util.stream.Collectors;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
/**
* A {@link CacheManager} delegator which wraps the
* {@link CacheManager#getCache(String)} and
* {@link CacheManager#getCacheNames()} to include the
* {@link TenantAware#getCurrentTenant()} when accessing a cache, so caches are
* seperated.
*
* Additionally it also provide functionality to retrieve all caches overall
* tenants at once, for monitoring and system access.
*
*
*
*
*/
public class TenantAwareCacheManager implements TenancyCacheManager {
private static final String TENANT_CACHE_DELIMITER = "|";
private final CacheManager delegate;
private final TenantAware tenantAware;
/**
* @param delegate
* the {@link CacheManager} to delegate to.
* @param tenantAware
* the tenant aware to retrieve the current tenant
*/
public TenantAwareCacheManager(final CacheManager delegate, final TenantAware tenantAware) {
this.delegate = delegate;
this.tenantAware = tenantAware;
}
@Override
public Cache getCache(final String name) {
final String currentTenant = tenantAware.getCurrentTenant().toUpperCase();
if (currentTenant.contains(TENANT_CACHE_DELIMITER)) {
return null;
}
return delegate.getCache(currentTenant + TENANT_CACHE_DELIMITER + name);
}
@Override
public Collection<String> getCacheNames() {
final String currentTenant = tenantAware.getCurrentTenant().toUpperCase();
if (currentTenant.contains(TENANT_CACHE_DELIMITER)) {
return Collections.emptyList();
}
return getCacheNames(currentTenant);
}
/**
* A direct access for retrieving all cache names overall tenants.
*
* @return all cache names without tenant check
*/
public Collection<String> getDirectCacheNames() {
return delegate.getCacheNames();
}
@Override
public Cache getDirectCache(final String name) {
return delegate.getCache(name);
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.hawkbit.server.cache.TenancyCacheManager#evictCaches(java.
* lang. String)
*/
@Override
public void evictCaches(final String tenant) {
getCacheNames(tenant)
.forEach(cachename -> delegate.getCache(tenant + TENANT_CACHE_DELIMITER + cachename).clear());
}
private Collection<String> getCacheNames(final String tenant) {
final String tenantWithDelimiter = tenant + TENANT_CACHE_DELIMITER;
return delegate.getCacheNames().parallelStream().filter(cacheName -> cacheName.startsWith(tenantWithDelimiter))
.map(cacheName -> cacheName.substring(tenantWithDelimiter.length())).collect(Collectors.toList());
}
}

View File

@@ -0,0 +1,38 @@
/**
* 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.eventbus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.eventbus.DeadEvent;
import com.google.common.eventbus.Subscribe;
/**
* Catches all dead events by means of events with no fitting subscriber on the
* bus.
*
*
*
*/
@EventSubscriber
public class DeadEventListener {
private static final Logger LOG = LoggerFactory.getLogger(DeadEventListener.class);
/**
* Listens for dead vents and prints them into LOG.
*
* @param event
* to print
*/
@Subscribe
public void listen(final DeadEvent event) {
LOG.info("DeadEvent on bus! {}", event.getEvent());
}
}

View File

@@ -0,0 +1,88 @@
/**
* 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.eventbus;
import java.lang.reflect.Method;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
/**
* An {@link BeanPostProcessor} implementation which registers all beans as a
* event bus subscriber if the classes are annotated with
* {@link EventSubscriber} and have at least one method annotated with the
* guava's {@link Subscribe} annoation.
*
*
*/
public class EventBusSubscriberProcessor implements BeanPostProcessor {
private static final Logger LOGGER = LoggerFactory.getLogger(EventBusSubscriberProcessor.class);
@Autowired
private EventBus eventBus;
/*
* (non-Javadoc)
*
* @see org.springframework.beans.factory.config.BeanPostProcessor#
* postProcessBeforeInitialization (java.lang.Object, java.lang.String)
*/
@Override
public Object postProcessBeforeInitialization(final Object bean, final String beanName) {
return bean;
}
/*
* (non-Javadoc)
*
* @see org.springframework.beans.factory.config.BeanPostProcessor#
* postProcessAfterInitialization( java.lang.Object, java.lang.String)
*/
@Override
public Object postProcessAfterInitialization(final Object bean, final String beanName) {
final Class<? extends Object> beanClass = bean.getClass();
final EventSubscriber eventSubscriber = beanClass.getAnnotation(EventSubscriber.class);
if (eventSubscriber != null) {
LOGGER.trace("Found bean {} with {} annotation ", bean.getClass().getName(),
EventSubscriber.class.getSimpleName());
final Method[] declaredMethods = beanClass.getDeclaredMethods();
for (final Method method : declaredMethods) {
final Subscribe subscriber = method.getAnnotation(Subscribe.class);
if (subscriber != null) {
LOGGER.trace("Found method {} for bean {} with {} annotation", method.getName(),
bean.getClass().getName(), Subscribe.class.getSimpleName());
eventBus.register(bean);
return bean;
}
}
}
if (eventSubscriber != null) {
LOGGER.debug("Found bean {} with {} annotation but without any method with necessary {} annotation",
bean.getClass().getName(), EventSubscriber.class.getSimpleName(), Subscribe.class.getSimpleName());
}
return bean;
}
/**
* package private setter for testing purposes.
*
* @param eventBus
* the event bus
*/
void setEventBus(final EventBus eventBus) {
this.eventBus = eventBus;
}
}

View File

@@ -0,0 +1,42 @@
/**
* 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.eventbus;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import org.springframework.stereotype.Service;
/**
* Marks an class as an event subscriber to listen on event on the event bus
* without explicit register this class to the event bus.
*
* <pre>
* &#064;EventSubscriber
* public class MySubscriber {
* &#064;Subscribe
* public void listen(MyEvent event) {
* System.out.println(&quot;event received: &quot; + event);
* }
* }
* </pre>
*
*
*
*
*/
@Target({ TYPE })
@Retention(RUNTIME)
@Service
public @interface EventSubscriber {
}

View File

@@ -0,0 +1,105 @@
/**
* 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.eventbus.event;
/**
* An abstract class of the {@link DistributedEvent} implementation which holds
* all the necessary information of distributing events to other nodes.
*
*
*
*
*/
public abstract class AbstractDistributedEvent implements DistributedEvent {
private static final long serialVersionUID = 1L;
private final long revision;
private String originNodeId;
private String nodeId;
private final String tenant;
/**
*
* @param revision
* the revision of this event
* @param tenant
* the tenant for this event
*/
protected AbstractDistributedEvent(final long revision, final String tenant) {
this.revision = revision;
this.tenant = tenant;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.hawkbit.server.eventbus.event.NodeAware#setOriginNodeId(java.
* lang. String)
*/
@Override
public void setOriginNodeId(final String originNodeId) {
this.originNodeId = originNodeId;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.hawkbit.server.eventbus.event.NodeAware#setNodeId(java.lang.
* String)
*/
@Override
public void setNodeId(final String nodeId) {
this.nodeId = nodeId;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.hawkbit.server.eventbus.event.NodeAware#getOriginNodeId()
*/
@Override
public String getOriginNodeId() {
return this.originNodeId;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.eventbus.event.NodeAware#getNodeId()
*/
@Override
public String getNodeId() {
return this.nodeId;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.eventbus.event.Event#getRevision()
*/
@Override
public long getRevision() {
return revision;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.eventbus.event.EntityEvent#getTenant()
*/
@Override
public String getTenant() {
return tenant;
}
}

View File

@@ -0,0 +1,75 @@
/**
* 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.eventbus.event;
import java.net.URI;
/**
* Event that gets sent when the assignment of a distribution set to a target
* gets canceled.
*
*
*
*/
public class CancelTargetAssignmentEvent {
private final String controllerId;
private final Long actionId;
private final URI targetAdress;
/**
* Creates a new {@link CancelTargetAssignmentEvent}.
*
* @param controllerId
* the ID of the controller
* @param actionId
* the action id of the assignment
* @param targetAdress
* the targetAdress of the target
*/
public CancelTargetAssignmentEvent(final String controllerId, final Long actionId, final URI targetAdress) {
this.controllerId = controllerId;
this.actionId = actionId;
this.targetAdress = targetAdress;
}
/**
* @return the action id of the assignment
*/
public Long getActionId() {
return actionId;
}
/**
* @return the controllerId of the Target which has been assigned to the
* distribution set
*/
public String getControllerId() {
return controllerId;
}
/**
*
* @return the targetr adress.
*/
public URI getTargetAdress() {
return targetAdress;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "TargetAssignDistributionSetEvent [targetAdress=" + targetAdress + ", controllerId=" + controllerId
+ ", actionId=" + actionId + "]";
}
}

View File

@@ -0,0 +1,24 @@
/**
* 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.eventbus.event;
/**
* Events to be published to refresh data on UI.
*
*
*
*
*/
public enum CustomEvents {
TARGETS_CREATED_EVENT,
DISTRIBUTION_CREATED_EVENT
}

View File

@@ -0,0 +1,23 @@
/**
* 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.eventbus.event;
import java.io.Serializable;
/**
* Marks an event to as an distributed event which will be distributed to other
* nodes.
*
*
*
*
*/
public interface DistributedEvent extends Event, NodeAware, Serializable {
}

View File

@@ -0,0 +1,57 @@
/**
* 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.eventbus.event;
/**
* Event that contains an updated download progress for a given Action.
*
*
*
*
*/
public class DownloadProgressEvent extends AbstractDistributedEvent {
private static final long serialVersionUID = 1L;
private final Long statusId;
private final int progressPercent;
/**
* Constructor.
*
* @param tenant
* the tenant for this event
* @param statusId
* of {@link UpdateActionStatus}
* @param progressPercent
* number (1-100)
*/
public DownloadProgressEvent(final String tenant, final Long statusId, final int progressPercent) {
// the revision of the DownloadProgressEvent is just equal the
// progressPercentage due the
// percentage is going from 0 to 100.
super(statusId, tenant);
this.statusId = statusId;
this.progressPercent = progressPercent;
}
/**
* @return the statusId
*/
public Long getStatusId() {
return statusId;
}
/**
* @return the progressPercent
*/
public int getProgressPercent() {
return progressPercent;
}
}

View File

@@ -0,0 +1,48 @@
/**
* 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.eventbus.event;
/**
* An event interface which declares event types that an entity has been
* changed. {@link EntityEvent}s should not implement {@link DistributedEvent}
* due all {@link EntityEvent}s will be distributed to other nodes.
*
* Retrieving an {@link EntityEvent} on a different node the entity will be load
* lazy.
*
*
*
*
*/
public interface EntityEvent extends Event, NodeAware {
/**
* A typesafe way to retrieve the entity from the event, which might be
* loaded lazy in case the event has been distributed from another node.
*
* @param entityClass
* the class of the entity to retrieve
* @return the entity might be lazy loaded. Might be {@code null} in case
* the entity e.g. is queried lazy on a different node and has been
* already deleted from the database
* @throws ClassCastException
* in case a wrong entity class is given for this event
*/
<E> E getEntity(Class<E> entityClass);
/**
* An unsafe way to retrieve the entity from this event which might be
* loaded lazy in case the event has been distributed from another node.
*
* @return the entity might be lazy loaded. Might be {@code null} in case
* the entity e.g. is queried lazy on a different node and has been
* already deleted from the database
*/
Object getEntity();
}

View File

@@ -0,0 +1,32 @@
/**
* 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.eventbus.event;
/**
* An event declaration which holds an revision for each event so consumers have
* the chance to know if they might already retrieved an newer event.
*
*
*
*
*/
public interface Event {
/**
* @return the revision of this event which should be increment or each new
* event in case the event have a causalität. Might be {@code -1} in
* case the events does not provide any revision.
*/
long getRevision();
/**
* @return the tenant of the entity.
*/
String getTenant();
}

View File

@@ -0,0 +1,52 @@
/**
* 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.eventbus.event;
/**
* Interface to be implemented by events which are distributed to other nodes
* where it's necessary to know which node sent an event and which nodes
* retrieved the event from which node. Using the EventDistributor the
* implementation only needs to contain the necessary node IDs, setting and
* retrieving the node IDs is transparent by the EventDistributor so the event
* distributor does not hang in an endless loop of distributing the events which
* self posted.
*
*
*
*
*/
public interface NodeAware {
/**
* @return the origin node ID in case the event has been forwarded to other
* nodes or {@code null} if the event has not been forwarded to
* other nodes
*/
String getOriginNodeId();
/**
* @param originNodeId
* the origin node ID where this event has been sent originally
*/
void setOriginNodeId(String originNodeId);
/**
* @return the node ID which is processing this event locally, set by the
* EventDistributor so he can determine if this event has been
* received by another node and is processing on the current node.
*/
String getNodeId();
/**
* @param nodeId
* the ID of the node this event is processing.
*/
void setNodeId(String nodeId);
}

View File

@@ -0,0 +1,39 @@
/**
* 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.eventbus.event;
/**
*
*
*
*/
public class TargetDeletedEvent extends AbstractDistributedEvent {
private static final long serialVersionUID = 1L;
private final long targetId;
/**
* @param tenant
* the tenant for this event
* @param targetId
* the ID of the target which has been deleted
*/
public TargetDeletedEvent(final String tenant, final long targetId) {
super(-1, tenant);
this.targetId = targetId;
}
/**
* @return the targetId
*/
public long getTargetId() {
return targetId;
}
}

View File

@@ -0,0 +1,62 @@
/**
* 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.exception;
/**
* {@link GenericSpServerException} is thrown when a given entity in's actual
* and cannot be stored within the current session. Reason could be that it has
* been changed within another session.
*
*
*
*/
public class GenericSpServerException extends SpServerRtException {
private static final long serialVersionUID = 1L;
private static final SpServerError THIS_ERROR = SpServerError.SP_REPO_GENERIC_ERROR;
/**
* Constructor.
*/
public GenericSpServerException() {
super(THIS_ERROR);
}
/**
* Parameterized constructor.
*
* @param cause
* of the exception
*/
public GenericSpServerException(final Throwable cause) {
super(THIS_ERROR, cause);
}
/**
* Parameterized constructor.
*
* @param message
* custom error message
* @param cause
* of the exception
*/
public GenericSpServerException(final String message, final Throwable cause) {
super(message, THIS_ERROR, cause);
}
/**
* Parameterized constructor.
*
* @param message
* custom error message
*/
public GenericSpServerException(final String message) {
super(message, THIS_ERROR);
}
}

View File

@@ -0,0 +1,192 @@
/**
* 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.exception;
/**
*
*
*
* Define the Error code for Error handling
*
*/
public enum SpServerError {
/**
*
*/
SP_REPO_GENERIC_ERROR("hawkbit.server.error.repo.genericError", "unknown error occured"),
/**
*
*/
SP_REPO_ENTITY_ALRREADY_EXISTS("hawkbit.server.error.repo.entitiyAlreayExists",
"The given entity already exists in database"),
/**
*
*/
SP_REPO_ENTITY_NOT_EXISTS("hawkbit.server.error.repo.entitiyNotFound",
"The given entity does not exist in database"),
/**
*
*/
SP_REPO_CONCURRENT_MODIFICATION("hawkbit.server.error.repo.concurrentModification",
"The given entity has been changed by another user/session"),
/**
*
*/
SP_REST_SORT_PARAM_SYNTAX("hawkbit.server.error.rest.param.sortParamSyntax",
"The given sort paramter is not well formed"),
/**
*
*/
SP_REST_RSQL_SEARCH_PARAM_SYNTAX("hawkbit.server.error.rest.param.rsqlParamSyntax",
"The given search paramter is not well formed"),
/**
*
*/
SP_REST_RSQL_PARAM_INVALID_FIELD("hawkbit.server.error.rest.param.rsqlInvalidField",
"The given search parameter field does not exist"),
/**
*
*/
SP_REST_SORT_PARAM_INVALID_FIELD("hawkbit.server.error.rest.param.invalidField",
"The given sort parameter field does not exist"),
/**
*
*/
SP_REST_SORT_PARAM_INVALID_DIRECTION("hawkbit.server.error.rest.param.invalidDirection",
"The given sort parameter direction does not exist"),
/**
*
*/
SP_REST_BODY_NOT_READABLE("hawkbit.server.error.rest.body.notReadable",
"The given request body is not well formed"), SP_UI_SEARCH("hawkbit.server.error.ui.searchError",
"blabla :-)"),
/**
*
*/
SP_ARTIFACT_UPLOAD_FAILED("hawkbit.server.error.artifact.uploadFailed",
"Upload of artifact failed with internal server error."),
/**
*
*/
SP_ARTIFACT_UPLOAD_FAILED_MD5_MATCH("hawkbit.server.error.artifact.uploadFailed.checksum.md5.match",
"Upload of artifact failed as the provided MD5 checksum did not match with the provided artifact."),
/**
*
*/
SP_ARTIFACT_UPLOAD_FAILED_SHA1_MATCH("hawkbit.server.error.artifact.uploadFailed.checksum.sha1.match",
"Upload of artifact failed as the provided SHA1 checksum did not match with the provided artifact."),
/**
*
*/
SP_DS_CREATION_FAILED_MISSING_MODULE("hawkbit.server.error.distributionset.creationFailed.missingModule",
"Creation if Distribution Set failed as module is missing that is configured as mandatory."),
/**
*
*/
SP_ARTIFACT_UPLOAD_FILE_LIMIT_EXCEEDED("hawkbit.server.error.artifact.uploadFailed.sizelimitexceeded",
"Upload of artifact failed as the file exceeds its maximum permitted size"),
/**
*
*/
SP_INSUFFICIENT_PERMISSION("hawkbit.server.error.insufficientpermission", "Insufficient Permission"),
/**
*
*/
SP_ARTIFACT_DELETE_FAILED("hawkbit.server.error.artifact.deleteFailed",
"Deletion of artifact failed with internal server error."),
/**
*
*/
SP_ARTIFACT_LOAD_FAILED("hawkbit.server.error.artifact.loadFailed",
"Load of artifact failed with internal server error."),
/**
*
*/
SP_ACTION_STATUS_TO_MANY_ENTRIES("hawkbit.server.error.action.status.tooManyEntries",
"Too many status entries have been inserted."),
/**
*
*/
SP_ATTRIBUTES_TO_MANY_ENTRIES("hawkbit.server.error.target.attributes.tooManyEntries",
"Too many attribute entries have been inserted."),
/**
*
*/
SP_ACTION_NOT_CANCELABLE("hawkbit.server.error.action.notcancelable",
"Only active actions which are in status pending are canceable"),
/**
*
*/
SP_DS_INCOMPLETE("hawkbit.server.error.distributionset.incomplete",
"Distribution set is assigned to a a target that is incomplete (i.e. mandatory modules are missing)"),
/**
*
*/
SP_DS_TYPE_UNDEFINED("hawkbit.server.error.distributionset.type.undefined",
"Distribution set type is not yet defined. Modules cannot be added until definition."),
/**
*
*/
SP_DS_MODULE_UNSUPPORTED("hawkbit.server.error.distributionset.modules.unsupported",
"Distribution set type does not contain the given module, i.e. is incompatible."),
/**
*
*/
SP_REPO_TENANT_NOT_EXISTS("hawkbit.server.error.repo.tenantNotExists",
"The entity cannot be inserted due the tenant does not exists"),
/**
*
*/
SP_ENTITY_LOCKED("hawkbit.server.error.entitiylocked", "The given entity is locked by the server."),
/**
*
*/
SP_REPO_ENTITY_READ_ONLY("hawkbit.server.error.entityreadonly",
"The given entity is read only and the change cannot be completed.");
private final String key;
private final String message;
/*
* Repository side Error codes
*/
private SpServerError(final String errorKey, final String message) {
key = errorKey;
this.message = message;
}
public String getKey() {
return key;
}
public String getMessage() {
return message;
}
}

View File

@@ -0,0 +1,80 @@
/**
* 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.exception;
/**
*
*
*
* Generic Custom Exception to wrap the Runtime and checked exception
*
*/
public abstract class SpServerRtException extends RuntimeException {
private static final long serialVersionUID = 1L;
private final SpServerError error;
/**
* Parameterized constructor.
*
* @param error
* detail
*/
public SpServerRtException(final SpServerError error) {
super(error.getMessage());
this.error = error;
}
/**
* Parameterized constructor.
*
* @param message
* custom error message
* @param error
* detail
*/
public SpServerRtException(final String message, final SpServerError error) {
super(message);
this.error = error;
}
/**
* Parameterized constructor.
*
* @param message
* custom error message
* @param error
* detail
* @param cause
* of the exception
*/
public SpServerRtException(final String message, final SpServerError error, final Throwable cause) {
super(message, cause);
this.error = error;
}
/**
* Parameterized constructor.
*
* @param error
* detail
* @param cause
* of the exception
*/
public SpServerRtException(final SpServerError error, final Throwable cause) {
super(error.getMessage(), cause);
this.error = error;
}
public SpServerError getError() {
return error;
}
}

View File

@@ -0,0 +1,80 @@
/**
* 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.repository;
/**
* Sort fields for {@link ActionRest}.
*
*
*
*
*/
public enum ActionFields implements FieldNameProvider, FieldValueConverter<ActionFields> {
/**
* The status field.
*/
STATUS("active"),
/**
* The id field.
*/
ID("id");
private static final String ACTIVE = "pending";
private static final String INACTIVE = "finished";
private final String fieldName;
private ActionFields(final String fieldName) {
this.fieldName = fieldName;
}
@Override
public String getFieldName() {
return fieldName;
}
@Override
public Object convertValue(final ActionFields e, final String value) {
switch (e) {
case STATUS:
return convertStatusValue(value);
default:
return value;
}
}
private Object convertStatusValue(final String value) {
final String trimmedValue = value.trim();
if (trimmedValue.equalsIgnoreCase(ACTIVE)) {
return 1;
} else if (trimmedValue.equalsIgnoreCase(INACTIVE)) {
return 0;
} else {
return null;
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.hawkbit.server.rest.resource.model.FieldValueConverter#
* possibleValues(java.lang.Enum)
*/
@Override
public String[] possibleValues(final ActionFields e) {
switch (e) {
case STATUS:
return new String[] { ACTIVE, INACTIVE };
default:
return new String[0];
}
}
}

View File

@@ -0,0 +1,39 @@
/**
* 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.repository;
/**
* Sort fields for {@link ActionStatusRest}.
*
*
*
*
*/
public enum ActionStatusFields implements FieldNameProvider {
/**
* The type field.
*/
TYPE("type"),
/**
* The id field.
*/
ID("id");
private final String fieldName;
private ActionStatusFields(final String fieldName) {
this.fieldName = fieldName;
}
@Override
public String getFieldName() {
return fieldName;
}
}

View File

@@ -0,0 +1,51 @@
/**
* 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.repository;
/**
* Describing the fields of the DistributionSet model which can be used in the
* REST API e.g. for sorting etc.
*
*
*
*
*/
public enum DistributionSetFields implements FieldNameProvider {
/**
* The name field.
*/
NAME("name"),
/**
* The description field.
*/
DESCRIPTION("description"),
/**
* The version field.
*/
VERSION("version"),
/**
* The complete field.
*/
COMPLETE("complete"),
/**
* The id field.
*/
ID("id");
private final String fieldName;
private DistributionSetFields(final String fieldName) {
this.fieldName = fieldName;
}
@Override
public String getFieldName() {
return fieldName;
}
}

View File

@@ -0,0 +1,39 @@
/**
* 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.repository;
/**
* Sort fields for DistributionSetMetadata.
*
*
*
*
*/
public enum DistributionSetMetadataFields implements FieldNameProvider {
/**
* The value field.
*/
VALUE("value"),
/**
* The key field.
*/
KEY("key");
private final String fieldName;
private DistributionSetMetadataFields(final String fieldName) {
this.fieldName = fieldName;
}
@Override
public String getFieldName() {
return fieldName;
}
}

View File

@@ -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.repository;
/**
* Describing the fields of the DistributionSetType model which can be used in
* the REST API e.g. for sorting etc.
*
*
*
*
*/
public enum DistributionSetTypeFields implements FieldNameProvider {
/**
* The name field.
*/
NAME("name"),
/**
* The description field.
*/
DESCRIPTION("description"),
/**
* The type key field.
*/
KEY("key"),
/**
* The id field.
*/
ID("id");
private final String fieldName;
private DistributionSetTypeFields(final String fieldName) {
this.fieldName = fieldName;
}
@Override
public String getFieldName() {
return fieldName;
}
}

View File

@@ -0,0 +1,26 @@
/**
* 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.repository;
/**
* An interface for declaring the name of the field described in the database
* which is used as string representation of the field, e.g. for sorting the
* fields over REST.
*
*
*
*/
public interface FieldNameProvider {
/**
* @return the string representation of the underlying persistence field
* name e.g. in case of sorting. Never {@code null}.
*/
String getFieldName();
}

View File

@@ -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.repository;
/**
* A value convert which converts given string based values into an object which
* can be used for building generic queries. Mapping external API values e.g.
* REST API to inside representation on database. E.g. mapping 'pending' or
* 'finished' values in rest queries to {@link TargetAction#isActive()} boolean
* value.
*
*
*
* @param <T>
* the enum parameter
*
*/
public interface FieldValueConverter<T extends Enum<T>> {
/**
* converts the given {@code value} into the representation to build a
* generic query.
*
* @param e
* the enum to build the value for
* @param value
* the value in string representation
* @return the converted object or {@code null} if conversation fails, if
* given enum does not need to be converted the the unmodified
* {@code value} is returned.
*/
Object convertValue(final T e, final String value);
/**
* returns the possible values associated with the given enum type.
*
* @param e
* the enum type to retrieve the possible values
* @return the possible values for a specific enum or {@code null}
*/
String[] possibleValues(final T e);
}

View File

@@ -0,0 +1,51 @@
/**
* 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.repository;
/**
* Describing the fields of the SoftwareModule model which can be used in the
* REST API e.g. for sorting etc.
*
*
*
*
*/
public enum SoftwareModuleFields implements FieldNameProvider {
/**
* The name field.
*/
NAME("name"),
/**
* The description field.
*/
DESCRIPTION("description"),
/**
* The description field.
*/
VERSION("version"),
/**
* The type field of the software module.
*/
TYPE("type.key"),
/**
* The id field.
*/
ID("id");
private final String fieldName;
private SoftwareModuleFields(final String fieldName) {
this.fieldName = fieldName;
}
@Override
public String getFieldName() {
return fieldName;
}
}

View File

@@ -0,0 +1,39 @@
/**
* 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.repository;
/**
* Sort fields for SoftwareModuleMetadata.
*
*
*
*
*/
public enum SoftwareModuleMetadataFields implements FieldNameProvider {
/**
* The value field.
*/
VALUE("value"),
/**
* The key field.
*/
KEY("key");
private final String fieldName;
private SoftwareModuleMetadataFields(final String fieldName) {
this.fieldName = fieldName;
}
@Override
public String getFieldName() {
return fieldName;
}
}

View File

@@ -0,0 +1,51 @@
/**
* 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.repository;
/**
* Describing the fields of the SoftwareModuleType model which can be used in
* the REST API e.g. for sorting etc.
*
*
*
*
*/
public enum SoftwareModuleTypeFields implements FieldNameProvider {
/**
* The name field.
*/
NAME("name"),
/**
* The description field.
*/
DESCRIPTION("description"),
/**
* The type key field.
*/
KEY("key"),
/**
* The id field.
*/
ID("id"),
/**
* The max ds assignments field.
*/
MAX("maxAssignments");
private final String fieldName;
private SoftwareModuleTypeFields(final String fieldName) {
this.fieldName = fieldName;
}
@Override
public String getFieldName() {
return fieldName;
}
}

View File

@@ -0,0 +1,52 @@
/**
* 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.repository;
/**
* Describing the fields of the Target model which can be used in the REST API
* e.g. for sorting etc.
*
*
*
*
*/
public enum TargetFields implements FieldNameProvider {
/**
* The name field.
*/
NAME("name"),
/**
* The description field.
*/
DESCRIPTION("description"),
/**
* The controllerId field.
*/
CONTROLLERID("controllerId"),
/**
* The updateStatus field.
*/
UPDATESTATUS("targetInfo.updateStatus"),
/**
* The ip-address field.
*/
IPADDRESS("targetInfo.ipAddress");
private final String fieldName;
private TargetFields(final String fieldName) {
this.fieldName = fieldName;
}
@Override
public String getFieldName() {
return fieldName;
}
}

View File

@@ -0,0 +1,65 @@
/**
* 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.tenancy;
/**
* Interface for components that are aware of the application's current tenant.
*
*
*
*
*/
public interface TenantAware {
/**
* Implementation might retrieve the current tenant from a session or
* thread-local.
*
* @return the current tenant
*/
String getCurrentTenant();
/**
* Gives the possibility to run a certain code under a specific given
* {@code tenant}. Only the given {@link TenantRunner} is executed under the
* specific tenant e.g. under control of an {@link ThreadLocal}. After the
* {@link TenantRunner} it must be ensured that the original tenant before
* this invocation is reset.
*
* @param tenant
* the tenant which the specific code should run
* @param tenantRunner
* the runner which is implemented to run this specific code
* under the given tenant
* @return the return type of the {@link TenantRunner}
* @throws any
* kind of {@link RuntimeException}
*/
<T> T runAsTenant(final String tenant, TenantRunner<T> tenantRunner);
/**
* An {@link TenantRunner} interface which allows to run specific code under
* a given tenant by using the
* {@link TenantAware#runAsTenant(String, TenantRunner)}.
*
*
*
*
* @param <T>
* the return type of the runner
*/
interface TenantRunner<T> {
/**
* Called to run specific code and a given tenant.
*
* @return the return of the code block running under a certain tenant
*/
T run();
}
}

View File

@@ -0,0 +1,91 @@
/**
* 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.tenancy.configuration;
/**
* An enum which defines the tenant specific configurations which can be
* configured for each tenant seperately.
*
*
*
*
*/
public enum TenantConfigurationKey {
/**
* boolean value {@code true} {@code false}.
*/
AUTHENTICATION_MODE_HEADER_ENABLED("authentication.header.enabled",
"hawkbit.server.controller.security.authentication.header.enabled", Boolean.FALSE.toString()),
/**
*
*/
AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME("authentication.header.authority",
"hawkbit.server.controller.security.authentication.header.authority", Boolean.FALSE.toString()),
/**
* boolean value {@code true} {@code false}.
*/
AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED("authentication.targettoken.enabled",
"hawkbit.server.controller.security.authentication.targettoken.enabled", Boolean.FALSE.toString()),
/**
* boolean value {@code true} {@code false}.
*/
AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED("authentication.gatewaytoken.enabled",
"hawkbit.server.controller.security.authentication.gatewaytoken.enabled", Boolean.FALSE.toString()),
/**
* string value which holds the name of the security token key.
*/
AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME("authentication.gatewaytoken.name",
"hawkbit.server.controller.security.authentication.gatewaytoken.name", null),
/**
* string value which holds the actual security-key of the gateway security
* token.
*/
AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY("authentication.gatewaytoken.key",
"hawkbit.server.controller.security.authentication.gatewaytoken.key", null);
private final String keyName;
private final String defaultKeyName;
private final String defaultValue;
/**
* @param key
* the property key name
* @param allowedValues
* the allowed values for this specific key
*/
private TenantConfigurationKey(final String key, final String defaultKeyName, final String defaultValue) {
this.keyName = key;
this.defaultKeyName = defaultKeyName;
this.defaultValue = defaultValue;
}
/**
* @return the keyName
*/
public String getKeyName() {
return keyName;
}
/**
* @return the defaultKeyName
*/
public String getDefaultKeyName() {
return defaultKeyName;
}
/**
* @return the defaultValue
*/
public String getDefaultValue() {
return defaultValue;
}
}