Skip to content

Commit

Permalink
Added new field for the adapter health status
Browse files Browse the repository at this point in the history
  • Loading branch information
mackdk committed May 6, 2024
1 parent 7454508 commit 0797994
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
4 changes: 4 additions & 0 deletions java/code/src/com/suse/cloud/CloudPaygManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,13 @@ private boolean detectIsCompliant() {
if (complainceInfo.isAnyPackageModified()) {
LOG.error("Some packages have been modified and cannot be trusted.");
}

if (!complainceInfo.isBillingAdapterRunning()) {
LOG.error("The CSP Billing Adapter service is not active.");
}
else if (!complainceInfo.isBillingAdapterHealthy()) {
LOG.error("The CSP Billing Adapter service has errors.");
}

return false;
}
Expand Down
19 changes: 16 additions & 3 deletions java/code/src/com/suse/cloud/PaygComplainceInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ public class PaygComplainceInfo {

private final boolean billingAdapterRunning;

@SerializedName("billingServiceStatus")
private final boolean billingAdapterHealthy;

private final long timestamp;

/**
* Creates the compliance info for a BYOS instance.
*/
public PaygComplainceInfo() {
// By default, assume it's a compliant BYOS instance
this(CloudProvider.None, false, false, true);
this(CloudProvider.None, false, false, true, true);
}

/**
Expand All @@ -56,17 +59,20 @@ public PaygComplainceInfo() {
* @param isPayg if the instance is PAYG
* @param hasModifiedPackages if some packages are modified
* @param isAdapterRunning if the required billing adapter service is running
* @param isAdapterHealthy if the required billing adapter service is healthy. The value is forced to
* <code>false</code> when the other parameter <code>isAdapterRunning</code> is set to false.
*/
public PaygComplainceInfo(CloudProvider provider, boolean isPayg, boolean hasModifiedPackages,
boolean isAdapterRunning) {
boolean isAdapterRunning, boolean isAdapterHealthy) {
paygInstance = isPayg;

cloudProvider = provider;
anyPackageModified = hasModifiedPackages;
billingAdapterRunning = isAdapterRunning;
billingAdapterHealthy = isAdapterRunning && isAdapterHealthy;

// Set the compliant flag accordingly to the value received
compliant = billingAdapterRunning && !anyPackageModified;
compliant = billingAdapterRunning && billingAdapterHealthy && !anyPackageModified;

timestamp = Instant.now().getEpochSecond();
}
Expand All @@ -91,6 +97,10 @@ public boolean isBillingAdapterRunning() {
return billingAdapterRunning;
}

public boolean isBillingAdapterHealthy() {
return billingAdapterHealthy;
}

public Instant getTimestamp() {
return Instant.ofEpochSecond(timestamp);
}
Expand All @@ -110,6 +120,7 @@ public boolean equals(Object o) {
.append(compliant, that.compliant)
.append(anyPackageModified, that.anyPackageModified)
.append(billingAdapterRunning, that.billingAdapterRunning)
.append(billingAdapterHealthy, that.billingAdapterHealthy)
.append(timestamp, that.timestamp)
.append(cloudProvider, that.cloudProvider)
.isEquals();
Expand All @@ -123,6 +134,7 @@ public int hashCode() {
.append(cloudProvider)
.append(anyPackageModified)
.append(billingAdapterRunning)
.append(billingAdapterHealthy)
.append(timestamp)
.toHashCode();
}
Expand All @@ -135,6 +147,7 @@ public String toString() {
.append("cloudProvider", getCloudProvider())
.append("anyPackageModified", isAnyPackageModified())
.append("billingAdapterRunning", isBillingAdapterRunning())
.append("billingAdapterHealthy", isBillingAdapterHealthy())
.append("timestamp", getTimestamp())
.toString();
}
Expand Down
9 changes: 9 additions & 0 deletions java/code/src/com/suse/cloud/test/CloudPaygManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ public void testRefreshIsCompliant() {
assertTrue(cpm.checkRefreshCache(false), "Not refreshed");
assertFalse(cpm.isCompliant(), "Unexpected: Is compliant");

// test 7 - billing adapter report errors
cpm = new TestCloudPaygManagerBuilder()
.withPaygInstance()
.withBillingAdapterRunning(false)
.build();

assertTrue(cpm.checkRefreshCache(false), "Not refreshed");
assertFalse(cpm.isCompliant(), "Unexpected: Is compliant");

cpm = new TestCloudPaygManagerBuilder()
.withPaygInstance()
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class TestCloudPaygManagerBuilder {
private boolean payg;
private String billingDataServiceStatus;
private boolean billingAdapterRunning;
private boolean billingAdapterHealthy;
private boolean packageModified;
private Xor<TaskomaticApiException, Map<String, Object>> dimensionComputationSchedule;
private boolean sccCredentials;
Expand All @@ -46,7 +47,7 @@ public TestCloudPaygManagerBuilder() {
withCloudProvider(CloudProvider.None)
.withByosInstance()
.withBillingDataServiceStatus("online")
.withBillingAdapterRunning()
.withBillingAdapterRunning(true)
.withOriginalPackages()
.withDimensionComputationScheduled(Map.of())
.withSCCCredentials();
Expand Down Expand Up @@ -80,11 +81,13 @@ public TestCloudPaygManagerBuilder withBillingDataServiceStatus(String status) {

public TestCloudPaygManagerBuilder withBillingAdapterDown() {
billingAdapterRunning = false;
billingAdapterHealthy = false;
return this;
}

public TestCloudPaygManagerBuilder withBillingAdapterRunning() {
public TestCloudPaygManagerBuilder withBillingAdapterRunning(boolean isHealthy) {
billingAdapterRunning = true;
billingAdapterHealthy = isHealthy;
return this;
}

Expand Down Expand Up @@ -155,7 +158,7 @@ protected String requestUrl(String url) {
@Override
protected PaygComplainceInfo getInstanceComplianceInfo() {
return new PaygComplainceInfo(
cloudProvider, payg, packageModified, billingAdapterRunning
cloudProvider, payg, packageModified, billingAdapterRunning, billingAdapterHealthy
);
}
};
Expand Down

0 comments on commit 0797994

Please sign in to comment.