Skip to content

Commit

Permalink
Merge pull request #520 from bsinno/fix_dmf_model_name_clashes
Browse files Browse the repository at this point in the history
Rename DMF model classes to avoid name clashes with the repository.
  • Loading branch information
kaizimmerm authored May 19, 2017
2 parents 78df803 + 806491d commit 4dd422c
Show file tree
Hide file tree
Showing 33 changed files with 271 additions and 274 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import org.apache.http.conn.ssl.SSLContextBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.eclipse.hawkbit.dmf.json.model.Artifact;
import org.eclipse.hawkbit.dmf.json.model.SoftwareModule;
import org.eclipse.hawkbit.dmf.json.model.DmfArtifact;
import org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule;
import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice.Protocol;
import org.eclipse.hawkbit.simulator.UpdateStatus.ResponseStatus;
import org.eclipse.hawkbit.simulator.amqp.SpSenderService;
Expand Down Expand Up @@ -94,7 +94,7 @@ public class DeviceSimulatorUpdater {
* process has been finished
*/
public void startUpdate(final String tenant, final String id, final long actionId, final String swVersion,
final List<SoftwareModule> modules, final String targetSecurityToken, final UpdaterCallback callback) {
final List<DmfSoftwareModule> modules, final String targetSecurityToken, final UpdaterCallback callback) {
AbstractSimulatedDevice device = repository.get(tenant, id);

// plug and play - non existing device will be auto created
Expand All @@ -109,7 +109,7 @@ public void startUpdate(final String tenant, final String id, final long actionI
device.setSwversion(swVersion);
} else {
device.setSwversion(
modules.stream().map(SoftwareModule::getModuleVersion).collect(Collectors.joining(", ")));
modules.stream().map(DmfSoftwareModule::getModuleVersion).collect(Collectors.joining(", ")));
}
device.setTargetSecurityToken(targetSecurityToken);
eventbus.post(new InitUpdate(device));
Expand All @@ -134,11 +134,11 @@ private static final class DeviceSimulatorUpdateThread implements Runnable {
private final EventBus eventbus;
private final ScheduledExecutorService threadPool;
private final UpdaterCallback callback;
private final List<SoftwareModule> modules;
private final List<DmfSoftwareModule> modules;

private DeviceSimulatorUpdateThread(final AbstractSimulatedDevice device, final SpSenderService spSenderService,
final long actionId, final EventBus eventbus, final ScheduledExecutorService threadPool,
final UpdaterCallback callback, final List<SoftwareModule> modules) {
final UpdaterCallback callback, final List<DmfSoftwareModule> modules) {
this.device = device;
this.spSenderService = spSenderService;
this.actionId = actionId;
Expand Down Expand Up @@ -204,7 +204,7 @@ private static boolean isErrorResponse(final UpdateStatus status) {
}

private static void handleArtifact(final String targetToken, final List<UpdateStatus> status,
final Artifact artifact) {
final DmfArtifact artifact) {

if (artifact.getUrls().containsKey("HTTPS")) {
status.add(downloadUrl(artifact.getUrls().get("HTTPS"), targetToken, artifact.getHashes().getSha1(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.eclipse.hawkbit.dmf.amqp.api.EventTopic;
import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey;
import org.eclipse.hawkbit.dmf.amqp.api.MessageType;
import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest;
import org.eclipse.hawkbit.dmf.json.model.DmfDownloadAndUpdateRequest;
import org.eclipse.hawkbit.simulator.DeviceSimulatorRepository;
import org.eclipse.hawkbit.simulator.DeviceSimulatorUpdater;
import org.slf4j.Logger;
Expand Down Expand Up @@ -141,8 +141,8 @@ private void handleUpdateProcess(final Message message, final String thingId) {
final Map<String, Object> headers = messageProperties.getHeaders();
final String tenant = (String) headers.get(MessageHeaderKey.TENANT);

final DownloadAndUpdateRequest downloadAndUpdateRequest = convertMessage(message,
DownloadAndUpdateRequest.class);
final DmfDownloadAndUpdateRequest downloadAndUpdateRequest = convertMessage(message,
DmfDownloadAndUpdateRequest.class);
final Long actionId = downloadAndUpdateRequest.getActionId();
final String targetSecurityToken = downloadAndUpdateRequest.getTargetSecurityToken();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import org.eclipse.hawkbit.dmf.amqp.api.EventTopic;
import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey;
import org.eclipse.hawkbit.dmf.amqp.api.MessageType;
import org.eclipse.hawkbit.dmf.json.model.ActionStatus;
import org.eclipse.hawkbit.dmf.json.model.ActionUpdateStatus;
import org.eclipse.hawkbit.dmf.json.model.AttributeUpdate;
import org.eclipse.hawkbit.dmf.json.model.DmfActionStatus;
import org.eclipse.hawkbit.dmf.json.model.DmfActionUpdateStatus;
import org.eclipse.hawkbit.dmf.json.model.DmfAttributeUpdate;
import org.eclipse.hawkbit.simulator.SimulationProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -66,7 +66,7 @@ public SpSenderService(final RabbitTemplate rabbitTemplate, final AmqpProperties
* a description according the update process
*/
public void finishUpdateProcess(final SimulatedUpdate update, final List<String> updateResultMessages) {
final Message updateResultMessage = createUpdateResultMessage(update, ActionStatus.FINISHED,
final Message updateResultMessage = createUpdateResultMessage(update, DmfActionStatus.FINISHED,
updateResultMessages);
sendMessage(spExchange, updateResultMessage);
}
Expand Down Expand Up @@ -96,7 +96,7 @@ public void finishUpdateProcessWithError(final SimulatedUpdate update, final Lis
* the ID of the action for the error message
*/
public void sendErrorMessage(final String tenant, final List<String> updateResultMessages, final Long actionId) {
final Message message = createActionStatusMessage(tenant, ActionStatus.ERROR, updateResultMessages, actionId);
final Message message = createActionStatusMessage(tenant, DmfActionStatus.ERROR, updateResultMessages, actionId);
sendMessage(spExchange, message);
}

Expand All @@ -109,7 +109,7 @@ public void sendErrorMessage(final String tenant, final List<String> updateResul
* a warning description
*/
public void sendWarningMessage(final SimulatedUpdate update, final List<String> updateResultMessages) {
final Message message = createActionStatusMessage(update, updateResultMessages, ActionStatus.WARNING);
final Message message = createActionStatusMessage(update, updateResultMessages, DmfActionStatus.WARNING);
sendMessage(spExchange, message);
}

Expand All @@ -125,7 +125,7 @@ public void sendWarningMessage(final SimulatedUpdate update, final List<String>
* @param actionId
* the cached value
*/
public void sendActionStatusMessage(final String tenant, final ActionStatus actionStatus,
public void sendActionStatusMessage(final String tenant, final DmfActionStatus actionStatus,
final List<String> updateResultMessages, final Long actionId) {
final Message message = createActionStatusMessage(tenant, actionStatus, updateResultMessages, actionId);
sendMessage(message);
Expand Down Expand Up @@ -179,7 +179,7 @@ private Message attributeUpdateMessage(final String tenant, final String targetI
messagePropertiesForSP.setHeader(MessageHeaderKey.THING_ID, targetId);
messagePropertiesForSP.setContentType(MessageProperties.CONTENT_TYPE_JSON);
messagePropertiesForSP.setReplyTo(amqpProperties.getSenderForSpExchange());
final AttributeUpdate attributeUpdate = new AttributeUpdate();
final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate();

attributeUpdate.getAttributes().putAll(simulationProperties.getAttributes().stream().collect(
Collectors.toMap(SimulationProperties.Attribute::getKey, SimulationProperties.Attribute::getValue)));
Expand All @@ -206,7 +206,7 @@ private void sendMessage(final Message message) {
* a list of descriptions according the update process
*/
private void sendErrorgMessage(final SimulatedUpdate update, final List<String> updateResultMessages) {
final Message message = createActionStatusMessage(update, updateResultMessages, ActionStatus.ERROR);
final Message message = createActionStatusMessage(update, updateResultMessages, DmfActionStatus.ERROR);
sendMessage(spExchange, message);
}

Expand All @@ -222,11 +222,11 @@ private void sendErrorgMessage(final SimulatedUpdate update, final List<String>
* @param cacheValue
* the cacheValue value
*/
private Message createActionStatusMessage(final String tenant, final ActionStatus actionStatus,
private Message createActionStatusMessage(final String tenant, final DmfActionStatus actionStatus,
final List<String> updateResultMessages, final Long actionId) {
final MessageProperties messageProperties = new MessageProperties();
final Map<String, Object> headers = messageProperties.getHeaders();
final ActionUpdateStatus actionUpdateStatus = new ActionUpdateStatus(actionId, actionStatus);
final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(actionId, actionStatus);
headers.put(MessageHeaderKey.TYPE, MessageType.EVENT.name());
headers.put(MessageHeaderKey.TENANT, tenant);
headers.put(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
Expand All @@ -236,11 +236,11 @@ private Message createActionStatusMessage(final String tenant, final ActionStatu
return convertMessage(actionUpdateStatus, messageProperties);
}

private Message createUpdateResultMessage(final SimulatedUpdate cacheValue, final ActionStatus actionStatus,
private Message createUpdateResultMessage(final SimulatedUpdate cacheValue, final DmfActionStatus actionStatus,
final List<String> updateResultMessages) {
final MessageProperties messageProperties = new MessageProperties();
final Map<String, Object> headers = messageProperties.getHeaders();
final ActionUpdateStatus actionUpdateStatus = new ActionUpdateStatus(cacheValue.getActionId(), actionStatus);
final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(cacheValue.getActionId(), actionStatus);
headers.put(MessageHeaderKey.TYPE, MessageType.EVENT.name());
headers.put(MessageHeaderKey.TENANT, cacheValue.getTenant());
headers.put(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
Expand All @@ -250,7 +250,7 @@ private Message createUpdateResultMessage(final SimulatedUpdate cacheValue, fina
}

private Message createActionStatusMessage(final SimulatedUpdate update, final List<String> updateResultMessages,
final ActionStatus status) {
final DmfActionStatus status) {
return createActionStatusMessage(update.getTenant(), status, updateResultMessages, update.getActionId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
import org.eclipse.hawkbit.cache.DownloadArtifactCache;
import org.eclipse.hawkbit.cache.DownloadIdCache;
import org.eclipse.hawkbit.cache.DownloadType;
import org.eclipse.hawkbit.dmf.json.model.Artifact;
import org.eclipse.hawkbit.dmf.json.model.ArtifactHash;
import org.eclipse.hawkbit.dmf.json.model.DownloadResponse;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource;
import org.eclipse.hawkbit.dmf.json.model.DmfArtifact;
import org.eclipse.hawkbit.dmf.json.model.DmfArtifactHash;
import org.eclipse.hawkbit.dmf.json.model.DmfDownloadResponse;
import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken;
import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken.FileResource;
import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.AmqpRejectAndDontRequeueException;
Expand Down Expand Up @@ -120,7 +121,7 @@ public Message onAuthenticationRequest(final Message message) {
* of the artifact to verify if the given target is allowed to
* download it
*/
private void checkIfArtifactIsAssignedToTarget(final TenantSecurityToken secruityToken, final String sha1Hash) {
private void checkIfArtifactIsAssignedToTarget(final DmfTenantSecurityToken secruityToken, final String sha1Hash) {

if (secruityToken.getControllerId() != null) {
checkByControllerId(sha1Hash, secruityToken.getControllerId());
Expand Down Expand Up @@ -154,8 +155,7 @@ private void checkByControllerId(final String sha1Hash, final String controllerI
LOG.info("download security check for target {} and artifact {} granted", controllerId, sha1Hash);
}

private Optional<org.eclipse.hawkbit.repository.model.Artifact> findArtifactByFileResource(
final FileResource fileResource) {
private Optional<Artifact> findArtifactByFileResource(final FileResource fileResource) {

if (fileResource == null) {
return Optional.empty();
Expand All @@ -182,29 +182,28 @@ private Optional<org.eclipse.hawkbit.repository.model.Artifact> findArtifactByFi
return Optional.empty();
}

private static Artifact convertDbArtifact(final DbArtifact dbArtifact) {
final Artifact artifact = new Artifact();
private static DmfArtifact convertDbArtifact(final DbArtifact dbArtifact) {
final DmfArtifact artifact = new DmfArtifact();
artifact.setSize(dbArtifact.getSize());
final DbArtifactHash dbArtifactHash = dbArtifact.getHashes();
artifact.setHashes(new ArtifactHash(dbArtifactHash.getSha1(), dbArtifactHash.getMd5()));
artifact.setHashes(new DmfArtifactHash(dbArtifactHash.getSha1(), dbArtifactHash.getMd5()));
return artifact;
}

private Message handleAuthenticationMessage(final Message message) {
final DownloadResponse authentificationResponse = new DownloadResponse();
final TenantSecurityToken secruityToken = convertMessage(message, TenantSecurityToken.class);
final DmfDownloadResponse authentificationResponse = new DmfDownloadResponse();
final DmfTenantSecurityToken secruityToken = convertMessage(message, DmfTenantSecurityToken.class);
final FileResource fileResource = secruityToken.getFileResource();
try {
SecurityContextHolder.getContext().setAuthentication(authenticationManager.doAuthenticate(secruityToken));

final String sha1Hash = findArtifactByFileResource(fileResource)
.map(org.eclipse.hawkbit.repository.model.Artifact::getSha1Hash)
.orElseThrow(() -> new EntityNotFoundException());
final String sha1Hash = findArtifactByFileResource(fileResource).map(Artifact::getSha1Hash)
.orElseThrow(EntityNotFoundException::new);

checkIfArtifactIsAssignedToTarget(secruityToken, sha1Hash);

final Artifact artifact = convertDbArtifact(artifactManagement.loadArtifactBinary(sha1Hash).orElseThrow(
() -> new EntityNotFoundException(org.eclipse.hawkbit.repository.model.Artifact.class, sha1Hash)));
final DmfArtifact artifact = convertDbArtifact(artifactManagement.loadArtifactBinary(sha1Hash)
.orElseThrow(() -> new EntityNotFoundException(Artifact.class, sha1Hash)));

authentificationResponse.setArtifact(artifact);
final String downloadId = UUID.randomUUID().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import javax.annotation.PostConstruct;

import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken;
import org.eclipse.hawkbit.dmf.json.model.DmfTenantSecurityToken;
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
Expand Down Expand Up @@ -121,7 +121,7 @@ private void addFilter() {
* the authentication request object
* @return the authentication object
*/
public Authentication doAuthenticate(final TenantSecurityToken securityToken) {
public Authentication doAuthenticate(final DmfTenantSecurityToken securityToken) {
resolveTenant(securityToken);
PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(null, null);
for (final PreAuthentificationFilter filter : filterChain) {
Expand All @@ -136,7 +136,7 @@ public Authentication doAuthenticate(final TenantSecurityToken securityToken) {

}

private void resolveTenant(final TenantSecurityToken securityToken) {
private void resolveTenant(final DmfTenantSecurityToken securityToken) {
if (securityToken.getTenant() == null) {
securityToken.setTenant(systemSecurityContext
.runAsSystem(() -> systemManagement.getTenantMetadata(securityToken.getTenantId()).getTenant()));
Expand All @@ -145,7 +145,7 @@ private void resolveTenant(final TenantSecurityToken securityToken) {
}

private static PreAuthenticatedAuthenticationToken createAuthentication(final PreAuthentificationFilter filter,
final TenantSecurityToken secruityToken) {
final DmfTenantSecurityToken secruityToken) {

if (!filter.isEnable(secruityToken)) {
return null;
Expand Down
Loading

0 comments on commit 4dd422c

Please sign in to comment.