RD: Extended RD to store 'reference' and error messages from EMS

This commit is contained in:
ipatini 2023-10-03 16:52:56 +03:00
parent 41823168a6
commit 2a4078611e
5 changed files with 88 additions and 7 deletions

View File

@ -249,6 +249,7 @@ public class RegistrationRequestProcessor implements IRegistrationRequestProcess
private void processResponse(@NonNull Map<String, Object> response) {
String requestId = response.getOrDefault("requestId", "").toString().trim();
String reference = response.getOrDefault("reference", "").toString().trim();
String status = response.getOrDefault("status", "").toString().trim();
String deviceIpAddress = response.getOrDefault("deviceIpAddress", "").toString().trim();
long timestamp = Long.parseLong(response.getOrDefault("timestamp", "-1").toString().trim());
@ -266,18 +267,27 @@ public class RegistrationRequestProcessor implements IRegistrationRequestProcess
registrationRequest.setStatus(newStatus);
String ipAddress = registrationRequest.getDevice().getIpAddress();
boolean isError = false;
if (StringUtils.equals(ipAddress, deviceIpAddress)) {
log.warn("processResponse: Device IP address do not match with that in request: id={}, ip-address={} != {}",
requestId, ipAddress, deviceIpAddress);
return;
String mesg = String.format("Device IP address do not match with that in request: id=%s, ip-address=%s != %s", requestId, ipAddress, deviceIpAddress);
log.warn("processResponse: {}", mesg);
registrationRequest.getMessages().add(mesg);
isError = true;
}
if (timestamp < registrationRequest.getRequestDate().toEpochMilli()) {
log.warn("processResponse: Response timestamp is older than Request's date: id={}, timestamp={} < {}",
requestId, timestamp, registrationRequest.getRequestDate());
return;
String mesg = String.format("Response timestamp is older than Request's date: id=%s, timestamp=%d < %s", requestId, timestamp, registrationRequest.getRequestDate());
log.warn("processResponse: {}", mesg);
registrationRequest.getMessages().add(mesg);
isError = true;
}
if (! "SUCCESS".equals(status)) {
log.warn("processResponse: Request status is not SUCCESS: id={}, timestamp={}, status={}", requestId, timestamp, status);
String mesg = String.format("Request status is not SUCCESS: id=%s, timestamp=%d, status=%s", requestId, timestamp, status);
log.warn("processResponse: {}", mesg);
registrationRequest.getMessages().add(mesg);
isError = true;
}
if (isError) {
registrationRequestService.update(registrationRequest);
return;
}
@ -307,6 +317,12 @@ public class RegistrationRequestProcessor implements IRegistrationRequestProcess
requestId, timestamp, processedDevInfo);
registrationRequest.getDevice().setDeviceInfo(processedDevInfo);
// Set node reference (meaningful only in case of Onboarding)
if (StringUtils.isNotBlank(reference) && currStatus==RegistrationRequestStatus.ONBOARDING_REQUESTED) {
registrationRequest.setNodeReference(reference.trim());
}
// Set new status
if (currStatus==RegistrationRequestStatus.DATA_COLLECTION_REQUESTED)
registrationRequest.setStatus(RegistrationRequestStatus.PENDING_AUTHORIZATION);
if (currStatus==RegistrationRequestStatus.ONBOARDING_REQUESTED)

View File

@ -15,6 +15,8 @@ public class ArchivedRegistrationRequest extends RegistrationRequest {
archivedRequest.setArchiveDate(registrationRequest.getArchiveDate());
archivedRequest.setStatus(registrationRequest.getStatus());
archivedRequest.setHistory(registrationRequest.getHistory());
archivedRequest.setNodeReference(registrationRequest.getNodeReference());
archivedRequest.getMessages().addAll(registrationRequest.getMessages());
return archivedRequest;
}
@ -28,6 +30,8 @@ public class ArchivedRegistrationRequest extends RegistrationRequest {
.archiveDate(this.getArchiveDate())
.status(this.getStatus())
.history(this.getHistory())
.nodeReference(this.getNodeReference())
.messages(this.getMessages())
.build();
}
}

View File

@ -1,12 +1,15 @@
package eu.nebulous.resource.discovery.registration.model;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
@Data
@ -23,4 +26,7 @@ public class RegistrationRequest {
private Instant archiveDate;
private RegistrationRequestStatus status;
private List<RegistrationRequestHistoryEntry> history;
private String nodeReference;
@Setter(AccessLevel.NONE)
private List<String> messages = new ArrayList<>();
}

View File

@ -108,6 +108,17 @@ function updateFormData(data) {
} else {
$(`[id="request#device#deviceInfo"]`).val( '' ).attr( 'rows', 2 );
}
// Update messages field
if (data.messages) {
var valStr = data.messages.join('\n').trim();
var rows = data.messages.length;
if (rows<2) rows = 2;
if (rows>50) rows = 50;
$(`[id="request#messages"]`).val( valStr ).attr( 'rows', rows );
} else {
$(`[id="request#messages"]`).val( '' ).attr( 'rows', 2 );
}
}
function flattenObject(ob) {
@ -202,6 +213,13 @@ function flattenObject(ob) {
<input type="text" readonly class="form-control-plaintext" id="request#requester" value="-">
</div>
</div>
<!-- Node reference (available after onboarding) -->
<div class="form-group row">
<label for="request#nodeReference" class="col-sm-2 col-form-label"><b>Node Reference</b></label>
<div class="col-sm-10">
<input type="text" readonly class="form-control-plaintext" id="request#nodeReference" value="-">
</div>
</div>
<!-- Request requestDate -->
<div class="form-group row">
<label for="request#requestDate" class="col-sm-2 col-form-label"><b>Request Date</b></label>
@ -230,6 +248,13 @@ function flattenObject(ob) {
<input type="text" readonly class="form-control-plaintext" id="request#archiveDate" value="-">
</div>
</div>
<!-- Request messages -->
<div class="form-group row">
<label for="request#messages" class="col-sm-2 col-form-label"><b>Messages</b></label>
<div class="col-sm-10">
<textarea readonly class="form-control-plaintext" id="request#messages"></textarea>
</div>
</div>
<div class="form-group row text-center bg-dark bg-opacity-25">
<h5>Device details</h5>

View File

@ -110,6 +110,17 @@ function updateFormData(data) {
} else {
$(`[id="request#device#deviceInfo"]`).val( '' ).attr( 'rows', 2 );
}
// Update messages field
if (data.messages) {
var valStr = data.messages.join('\n').trim();
var rows = data.messages.length;
if (rows<2) rows = 2;
if (rows>50) rows = 50;
$(`[id="request#messages"]`).val( valStr ).attr( 'rows', rows );
} else {
$(`[id="request#messages"]`).val( '' ).attr( 'rows', 2 );
}
}
function flattenObject(ob) {
@ -215,6 +226,11 @@ function saveRequestInfo() {
if (deviceInfo==='') deviceInfo = '{}';
root['device']['deviceInfo'] = JSON.parse( deviceInfo );
// Fix messages
var messages = $(`[id="request#messages"]`).val().trim();
if (messages==='') messages = '';
root['messages'] = messages.split(/\r\n|\r|\n/);
// Check request Id
if (requestId!=='' && requestId!==root.id) {
alert('Request id has been modified!');
@ -335,6 +351,13 @@ function sendRequestData(requestData) {
<input type="text" readonly class="form-control-plaintext" id="request#requester" value="-">
</div>
</div>
<!-- Node reference (available after onboarding) -->
<div class="form-group row">
<label for="request#nodeReference" class="col-sm-2 col-form-label"><b>Node Reference</b></label>
<div class="col-sm-10">
<input type="text" readonly class="form-control-plaintext" id="request#nodeReference" value="-">
</div>
</div>
<!-- Request requestDate -->
<div class="form-group row">
<label for="request#requestDate" class="col-sm-2 col-form-label"><b>Request Date</b></label>
@ -356,6 +379,13 @@ function sendRequestData(requestData) {
<input type="text" readonly class="form-control-plaintext" id="request#lastUpdateDate" value="-">
</div>
</div>
<!-- Request messages -->
<div class="form-group row">
<label for="request#messages" class="col-sm-2 col-form-label"><b>Messages</b></label>
<div class="col-sm-10">
<textarea readonly class="form-control-plaintext" id="request#messages"></textarea>
</div>
</div>
<div class="form-group row text-center bg-dark bg-opacity-25">
<h5>Device details</h5>