Feature extend system management resource with custom data (#423)
* Added map to system management and mgmt resource to extend the the rest resource with custom data Signed-off-by: Jonathan Philip Knoblauch <JonathanPhilip.Knoblauch@bosch-si.com> * Lazy initialization of hash map and typo fix Signed-off-by: Jonathan Philip Knoblauch <JonathanPhilip.Knoblauch@bosch-si.com> * Renamed the map to usageData Signed-off-by: Jonathan Philip Knoblauch <JonathanPhilip.Knoblauch@bosch-si.com> * Adapted hashcode and equals and now returning empty map Signed-off-by: Jonathan Philip Knoblauch <JonathanPhilip.Knoblauch@bosch-si.com> * Reduced duplicated code Signed-off-by: Jonathan Philip Knoblauch <JonathanPhilip.Knoblauch@bosch-si.com> * Removed the if statement Signed-off-by: Jonathan Philip Knoblauch <JonathanPhilip.Knoblauch@bosch-si.com> * Added separated method for lazy initialization Signed-off-by: Jonathan Philip Knoblauch <JonathanPhilip.Knoblauch@bosch-si.com>
This commit is contained in:
committed by
Michael Hirsch
parent
a00ea49e47
commit
d553716cda
@@ -8,6 +8,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.mgmt.json.model.systemmanagement;
|
package org.eclipse.hawkbit.mgmt.json.model.systemmanagement;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||||
@@ -25,6 +27,7 @@ public class MgmtSystemTenantServiceUsage {
|
|||||||
private long artifacts;
|
private long artifacts;
|
||||||
private long actions;
|
private long actions;
|
||||||
private long overallArtifactVolumeInBytes;
|
private long overallArtifactVolumeInBytes;
|
||||||
|
private Map<String, String> usageData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -71,4 +74,12 @@ public class MgmtSystemTenantServiceUsage {
|
|||||||
return tenantName;
|
return tenantName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getUsageData() {
|
||||||
|
return usageData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsageData(final Map<String, String> usageData) {
|
||||||
|
this.usageData = usageData;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,9 @@ public class MgmtSystemManagementResource implements MgmtSystemManagementRestApi
|
|||||||
result.setArtifacts(tenant.getArtifacts());
|
result.setArtifacts(tenant.getArtifacts());
|
||||||
result.setOverallArtifactVolumeInBytes(tenant.getOverallArtifactVolumeInBytes());
|
result.setOverallArtifactVolumeInBytes(tenant.getOverallArtifactVolumeInBytes());
|
||||||
result.setTargets(tenant.getTargets());
|
result.setTargets(tenant.getTargets());
|
||||||
|
if (!tenant.getUsageData().isEmpty()) {
|
||||||
|
result.setUsageData(tenant.getUsageData());
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository.report.model;
|
package org.eclipse.hawkbit.repository.report.model;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* System usage stats element for a tenant.
|
* System usage stats element for a tenant.
|
||||||
*
|
*
|
||||||
@@ -19,6 +24,7 @@ public class TenantUsage {
|
|||||||
private long artifacts;
|
private long artifacts;
|
||||||
private long actions;
|
private long actions;
|
||||||
private long overallArtifactVolumeInBytes;
|
private long overallArtifactVolumeInBytes;
|
||||||
|
private Map<String, String> usageData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -26,85 +32,74 @@ public class TenantUsage {
|
|||||||
* @param tenantName
|
* @param tenantName
|
||||||
*/
|
*/
|
||||||
public TenantUsage(final String tenantName) {
|
public TenantUsage(final String tenantName) {
|
||||||
super();
|
|
||||||
this.tenantName = tenantName;
|
this.tenantName = tenantName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return name of the tenant
|
|
||||||
*/
|
|
||||||
public String getTenantName() {
|
public String getTenantName() {
|
||||||
return tenantName;
|
return tenantName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return number of targets of the tenant
|
|
||||||
*/
|
|
||||||
public long getTargets() {
|
public long getTargets() {
|
||||||
return targets;
|
return targets;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param targets
|
|
||||||
* of the tenant
|
|
||||||
* @return updated tenant stats element
|
|
||||||
*/
|
|
||||||
public TenantUsage setTargets(final long targets) {
|
public TenantUsage setTargets(final long targets) {
|
||||||
this.targets = targets;
|
this.targets = targets;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return number of undeleted artifacts of the tenant
|
|
||||||
*/
|
|
||||||
public long getArtifacts() {
|
public long getArtifacts() {
|
||||||
return artifacts;
|
return artifacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public Map<String, String> getUsageData() {
|
||||||
* @param artifacts
|
return Collections.unmodifiableMap(getLazyUsageData());
|
||||||
* of tenant
|
}
|
||||||
* @return updated tenant stats element
|
|
||||||
*/
|
private Map<String, String> getLazyUsageData() {
|
||||||
|
if (usageData == null) {
|
||||||
|
usageData = Maps.newHashMap();
|
||||||
|
}
|
||||||
|
return usageData;
|
||||||
|
}
|
||||||
|
|
||||||
public TenantUsage setArtifacts(final long artifacts) {
|
public TenantUsage setArtifacts(final long artifacts) {
|
||||||
this.artifacts = artifacts;
|
this.artifacts = artifacts;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return current overallArtifactVolumeInBytes
|
|
||||||
*/
|
|
||||||
public long getOverallArtifactVolumeInBytes() {
|
public long getOverallArtifactVolumeInBytes() {
|
||||||
return overallArtifactVolumeInBytes;
|
return overallArtifactVolumeInBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param overallArtifactVolumeInBytes
|
|
||||||
* of the tenant in bytes
|
|
||||||
* @return updated tenant stats element
|
|
||||||
*/
|
|
||||||
public TenantUsage setOverallArtifactVolumeInBytes(final long overallArtifactVolumeInBytes) {
|
public TenantUsage setOverallArtifactVolumeInBytes(final long overallArtifactVolumeInBytes) {
|
||||||
this.overallArtifactVolumeInBytes = overallArtifactVolumeInBytes;
|
this.overallArtifactVolumeInBytes = overallArtifactVolumeInBytes;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return number of actions of tenant
|
|
||||||
*/
|
|
||||||
public long getActions() {
|
public long getActions() {
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param actions
|
|
||||||
* of the tenant
|
|
||||||
* @return updated tenant stats element
|
|
||||||
*/
|
|
||||||
public TenantUsage setActions(final long actions) {
|
public TenantUsage setActions(final long actions) {
|
||||||
this.actions = actions;
|
this.actions = actions;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a key and value as usage data to the system usage stats.
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
* the key to set
|
||||||
|
* @param value
|
||||||
|
* the value to set
|
||||||
|
* @return tenant stats element with new usage added
|
||||||
|
*/
|
||||||
|
public TenantUsage addUsageData(final String key, final String value) {
|
||||||
|
getLazyUsageData().put(key, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
@@ -114,6 +109,7 @@ public class TenantUsage {
|
|||||||
result = prime * result + (int) (overallArtifactVolumeInBytes ^ (overallArtifactVolumeInBytes >>> 32));
|
result = prime * result + (int) (overallArtifactVolumeInBytes ^ (overallArtifactVolumeInBytes >>> 32));
|
||||||
result = prime * result + (int) (targets ^ (targets >>> 32));
|
result = prime * result + (int) (targets ^ (targets >>> 32));
|
||||||
result = prime * result + ((tenantName == null) ? 0 : tenantName.hashCode());
|
result = prime * result + ((tenantName == null) ? 0 : tenantName.hashCode());
|
||||||
|
result = prime * result + ((usageData == null) ? 0 : usageData.hashCode());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,6 +137,9 @@ public class TenantUsage {
|
|||||||
if (targets != other.targets) {
|
if (targets != other.targets) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!this.getUsageData().equals(other.getUsageData())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (tenantName == null) {
|
if (tenantName == null) {
|
||||||
if (other.tenantName != null) {
|
if (other.tenantName != null) {
|
||||||
return false;
|
return false;
|
||||||
@@ -154,7 +153,8 @@ public class TenantUsage {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "TenantUsage [tenantName=" + tenantName + ", targets=" + targets + ", artifacts=" + artifacts
|
return "TenantUsage [tenantName=" + tenantName + ", targets=" + targets + ", artifacts=" + artifacts
|
||||||
+ ", actions=" + actions + ", overallArtifactVolumeInBytes=" + overallArtifactVolumeInBytes + "]";
|
+ ", actions=" + actions + ", overallArtifactVolumeInBytes=" + overallArtifactVolumeInBytes
|
||||||
|
+ ", usageData=" + usageData + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user