forked from eclipse/org.eclipse.sensinact.gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better error handling for pushed updates
This commit defines the exceptions that will be used to fail pushed updates, including bulk updates, and will be used to fail the returned promise. These exceptions return the error, and the original DTO so that users can attempt to work out what they did wrong. Signed-off-by: Tim Ward <timothyjward@apache.org>
- Loading branch information
1 parent
f651f4d
commit 77b7e28
Showing
15 changed files
with
987 additions
and
109 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
core/api/src/main/java/org/eclipse/sensinact/core/push/DataMappingException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Kentyou - initial implementation | ||
**********************************************************************/ | ||
package org.eclipse.sensinact.core.push; | ||
|
||
public class DataMappingException extends DataUpdateException { | ||
|
||
private static final long serialVersionUID = -1312692222440022024L; | ||
|
||
public DataMappingException(String modelPackageUri, String model, String provider, String service, String resource, | ||
Object originalDto, Throwable cause) { | ||
super(modelPackageUri, model, provider, service, resource, originalDto, | ||
"Unable to map DTO data into an update " + cause.getMessage(), cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
core/api/src/main/java/org/eclipse/sensinact/core/push/DataUpdateException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Kentyou - initial implementation | ||
**********************************************************************/ | ||
package org.eclipse.sensinact.core.push; | ||
|
||
import java.util.Objects; | ||
|
||
public class DataUpdateException extends Exception { | ||
|
||
private static final long serialVersionUID = -3948871450647637647L; | ||
private final String modelPackageUri; | ||
private final String model; | ||
private final String provider; | ||
private final String service; | ||
private final String resource; | ||
|
||
private final Object originalDto; | ||
|
||
public DataUpdateException(String modelPackageUri, String model, String provider, String service, String resource, | ||
Object originalDto, Throwable cause) { | ||
this(modelPackageUri, model, provider, service, resource, originalDto, | ||
cause == null ? getDefaultMessage(provider, service, resource) : cause.getMessage(), cause); | ||
} | ||
|
||
private static String getDefaultMessage(String provider, String service, String resource) { | ||
return String.format("Data update failed for %s/%s/%s", provider, service, resource); | ||
} | ||
|
||
protected DataUpdateException(String modelPackageUri, String model, String provider, String service, String resource, | ||
Object originalDto, String message, Throwable cause) { | ||
super(message, cause); | ||
Objects.requireNonNull(originalDto); | ||
this.modelPackageUri = modelPackageUri; | ||
this.model = model; | ||
this.provider = provider; | ||
this.service = service; | ||
this.resource = resource; | ||
this.originalDto = originalDto; | ||
} | ||
|
||
/** | ||
* @return The discovered modelPackageUri, or null | ||
*/ | ||
public String getModelPackageUri() { | ||
return modelPackageUri; | ||
} | ||
|
||
/** | ||
* @return The discovered model, or null | ||
*/ | ||
public String getModel() { | ||
return model; | ||
} | ||
|
||
/** | ||
* @return The discovered provider, or null | ||
*/ | ||
public String getProvider() { | ||
return provider; | ||
} | ||
|
||
/** | ||
* @return The discovered service, or null | ||
*/ | ||
public String getService() { | ||
return service; | ||
} | ||
|
||
/** | ||
* @return The discovered resource, or null | ||
*/ | ||
public String getResource() { | ||
return resource; | ||
} | ||
|
||
/** | ||
* @return The DTO that was being mapped | ||
*/ | ||
public Object getOriginalDto() { | ||
return originalDto; | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
core/api/src/main/java/org/eclipse/sensinact/core/push/FailedUpdatesException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Kentyou - initial implementation | ||
**********************************************************************/ | ||
package org.eclipse.sensinact.core.push; | ||
|
||
import static java.util.stream.Collectors.toUnmodifiableList; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Stream; | ||
|
||
public class FailedUpdatesException extends Exception { | ||
|
||
private static final long serialVersionUID = 558905737809687311L; | ||
|
||
private final List<DataUpdateException> failedUpdates; | ||
|
||
public FailedUpdatesException(DataUpdateException failedUpdate) { | ||
Objects.requireNonNull(failedUpdate); | ||
failedUpdates = List.of(failedUpdate); | ||
addSuppressed(failedUpdate); | ||
} | ||
|
||
public FailedUpdatesException(Stream<? extends DataUpdateException> failedUpdates) { | ||
Objects.requireNonNull(failedUpdates); | ||
this.failedUpdates = failedUpdates.collect(toUnmodifiableList()); | ||
this.failedUpdates.forEach(this::addSuppressed); | ||
} | ||
|
||
public List<DataUpdateException> getFailedUpdates() { | ||
return failedUpdates; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
core/impl/src/main/java/org/eclipse/sensinact/core/dto/impl/FailedMappingDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Kentyou - initial implementation | ||
**********************************************************************/ | ||
package org.eclipse.sensinact.core.dto.impl; | ||
|
||
public class FailedMappingDto extends AbstractUpdateDto { | ||
|
||
public Throwable mappingFailure; | ||
|
||
} |
Oops, something went wrong.