-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed exception throwing and limit checking
Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
- Loading branch information
Showing
12 changed files
with
202 additions
and
24 deletions.
There are no files selected for viewing
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
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
76 changes: 76 additions & 0 deletions
76
...pse/kapua/commons/configuration/exception/ServiceConfigurationLimitExceededException.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,76 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Eurotech and/or its affiliates and others | ||
* | ||
* 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: | ||
* Eurotech - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.kapua.commons.configuration.exception; | ||
|
||
import org.eclipse.kapua.commons.configuration.AbstractKapuaConfigurableResourceLimitedService; | ||
import org.eclipse.kapua.model.id.KapuaId; | ||
import org.eclipse.kapua.service.config.KapuaConfigurableService; | ||
|
||
/** | ||
* {@link KapuaConfigurationException} to {@code throw} when an update of a {@link AbstractKapuaConfigurableResourceLimitedService} | ||
* {@code maxNumberChildEntities} property exceeds available resources of the current scope. | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
public class ServiceConfigurationLimitExceededException extends KapuaConfigurationException { | ||
|
||
private final String servicePid; | ||
private final KapuaId scopeId; | ||
private final long limitExceededBy; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param servicePid The {@link KapuaConfigurableService} pid. | ||
* @param scopeId The scope {@link KapuaId} for which limit has been exceeded. | ||
* @param limitExceededBy The amount of exceed. | ||
* @since 2.0.0 | ||
*/ | ||
public ServiceConfigurationLimitExceededException(String servicePid, KapuaId scopeId, long limitExceededBy) { | ||
super(limitExceededBy < 1000000 ? KapuaConfigurationErrorCodes.LIMIT_EXCEEDED_BY : KapuaConfigurationErrorCodes.LIMIT_EXCEEDED, servicePid, scopeId, limitExceededBy); | ||
|
||
this.servicePid = servicePid; | ||
this.scopeId = scopeId; | ||
this.limitExceededBy = limitExceededBy; | ||
} | ||
|
||
/** | ||
* Gets the {@link KapuaConfigurableService} pid. | ||
* | ||
* @return he {@link KapuaConfigurableService} pid. | ||
* @since 2.0.0 | ||
*/ | ||
public String getServicePid() { | ||
return servicePid; | ||
} | ||
|
||
/** | ||
* Gets the scope {@link KapuaId} for which limit has been exceeded. | ||
* | ||
* @return The scope {@link KapuaId} for which limit has been exceeded. | ||
* @since 2.0.0 | ||
*/ | ||
public KapuaId getScopeId() { | ||
return scopeId; | ||
} | ||
|
||
/** | ||
* Gets the amount of exceed. | ||
* | ||
* @return the amount of exceed. | ||
* @since 2.0.0 | ||
*/ | ||
public long getLimitExceededBy() { | ||
return limitExceededBy; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...pua/commons/configuration/exception/ServiceConfigurationParentLimitExceededException.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,76 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Eurotech and/or its affiliates and others | ||
* | ||
* 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: | ||
* Eurotech - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.kapua.commons.configuration.exception; | ||
|
||
import org.eclipse.kapua.commons.configuration.AbstractKapuaConfigurableResourceLimitedService; | ||
import org.eclipse.kapua.model.id.KapuaId; | ||
import org.eclipse.kapua.service.config.KapuaConfigurableService; | ||
|
||
/** | ||
* {@link KapuaConfigurationException} to {@code throw} when an update of a {@link AbstractKapuaConfigurableResourceLimitedService} | ||
* {@code maxNumberChildEntities} property exceeds available resources of the parent scope. | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
public class ServiceConfigurationParentLimitExceededException extends KapuaConfigurationException { | ||
|
||
private final String servicePid; | ||
private final KapuaId parentScopeId; | ||
private final long limitExceededBy; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param servicePid The {@link KapuaConfigurableService} pid. | ||
* @param parentScopeId The parent scope {@link KapuaId} for which limit has been exceeded. | ||
* @param limitExceededBy The amount of exceed. | ||
* @since 2.0.0 | ||
*/ | ||
public ServiceConfigurationParentLimitExceededException(String servicePid, KapuaId parentScopeId, long limitExceededBy) { | ||
super(limitExceededBy < 1000000 ? KapuaConfigurationErrorCodes.PARENT_LIMIT_EXCEEDED_BY : KapuaConfigurationErrorCodes.PARENT_LIMIT_EXCEEDED, servicePid, parentScopeId, limitExceededBy); | ||
|
||
this.servicePid = servicePid; | ||
this.parentScopeId = parentScopeId; | ||
this.limitExceededBy = limitExceededBy; | ||
} | ||
|
||
/** | ||
* Gets the {@link KapuaConfigurableService} pid. | ||
* | ||
* @return he {@link KapuaConfigurableService} pid. | ||
* @since 2.0.0 | ||
*/ | ||
public String getServicePid() { | ||
return servicePid; | ||
} | ||
|
||
/** | ||
* Gets the parent scope {@link KapuaId} for which limit has been exceeded. | ||
* | ||
* @return The parent scope {@link KapuaId} for which limit has been exceeded. | ||
* @since 2.0.0 | ||
*/ | ||
public KapuaId getScopeId() { | ||
return parentScopeId; | ||
} | ||
|
||
/** | ||
* Gets the amount of exceed. | ||
* | ||
* @return the amount of exceed. | ||
* @since 2.0.0 | ||
*/ | ||
public long getLimitExceededBy() { | ||
return limitExceededBy; | ||
} | ||
} |
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
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
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
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