This is an automated email from the ASF dual-hosted git repository. lahirujayathilake pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit a8e37ed73918361bfbe40a66b081cc6905f7a896 Author: lahiruj <[email protected]> AuthorDate: Wed Oct 8 19:17:07 2025 -0400 account creation/inactivate and project reactivate handlers --- .../amie/handler/DataAccountCreateHandler.java | 93 +++++++++++++++++++++ .../handler/RequestAccountInactivateHandler.java | 95 ++++++++++++++++++++++ .../handler/RequestProjectReactivateHandler.java | 94 +++++++++++++++++++++ 3 files changed, 282 insertions(+) diff --git a/amie-decoder/src/main/java/org/apache/custos/amie/handler/DataAccountCreateHandler.java b/amie-decoder/src/main/java/org/apache/custos/amie/handler/DataAccountCreateHandler.java new file mode 100644 index 000000000..7138e8c78 --- /dev/null +++ b/amie-decoder/src/main/java/org/apache/custos/amie/handler/DataAccountCreateHandler.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.custos.amie.handler; + +import com.fasterxml.jackson.databind.JsonNode; +import org.apache.custos.amie.client.AmieClient; +import org.apache.custos.amie.model.PacketEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import org.springframework.util.Assert; + +import java.util.HashMap; +import java.util.Map; + +/** + * Handles the 'data_account_create' packet. + * <p> + * This packet is the third step in the account creation transaction. + */ +@Component +public class DataAccountCreateHandler implements PacketHandler { + + private static final Logger log = LoggerFactory.getLogger(DataAccountCreateHandler.class); + + private final AmieClient amieClient; + + public DataAccountCreateHandler(AmieClient amieClient) { + this.amieClient = amieClient; + } + + @Override + public String supportsType() { + return "data_account_create"; + } + + @Override + public void handle(JsonNode packetJson, PacketEntity packetEntity) { + log.info("Starting 'data_account_create' handler for packet amie_id [{}].", packetEntity.getAmieId()); + + JsonNode body = packetJson.path("body"); + String projectId = body.path("ProjectID").asText(); + String personId = body.path("PersonID").asText(); + JsonNode dnList = body.path("DnList"); + + Assert.hasText(projectId, "'ProjectID' must not be empty."); + Assert.hasText(personId, "'PersonID' must not be empty."); + log.info("Packet validated. ProjectID: [{}], PersonID: [{}].", projectId, personId); + + + // TODO - perform the business logic + // - find the user's record by 'personId' (localID) and update the distinguished names (dnList) + if (dnList.isArray() && !dnList.isEmpty()) { + log.info("Received DnList for user [{}]. In a real implementation, this would be saved to the user's profile.", personId); + // TODO userService.updateUserDnList(personId, dnList); + } + + // Send the 'inform_transaction_complete' reply to close the transaction. + sendSuccessReply(packetEntity.getAmieId()); + } + + private void sendSuccessReply(long packetRecId) { + Map<String, Object> reply = new HashMap<>(); + Map<String, Object> itcBody = new HashMap<>(); + + itcBody.put("StatusCode", "Success"); + itcBody.put("DetailCode", 1); + itcBody.put("Message", "Transaction completed successfully by handler."); + + reply.put("type", "inform_transaction_complete"); + reply.put("body", itcBody); + + amieClient.replyToPacket(packetRecId, reply); + + log.info("Successfully sent 'inform_transaction_complete' for data_account_create packet_rec_id [{}].", packetRecId); + } +} diff --git a/amie-decoder/src/main/java/org/apache/custos/amie/handler/RequestAccountInactivateHandler.java b/amie-decoder/src/main/java/org/apache/custos/amie/handler/RequestAccountInactivateHandler.java new file mode 100644 index 000000000..0288706c7 --- /dev/null +++ b/amie-decoder/src/main/java/org/apache/custos/amie/handler/RequestAccountInactivateHandler.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.custos.amie.handler; + +import com.fasterxml.jackson.databind.JsonNode; +import org.apache.custos.amie.client.AmieClient; +import org.apache.custos.amie.model.PacketEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import org.springframework.util.Assert; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Handles the 'request_account_inactivate' AMIE packet. + * <p> + * This transaction asks the local site to inactivate a user's association with a specific project. + * Upon successful local processing, it sends a 'notify_account_inactivate' reply. + */ +@Component +public class RequestAccountInactivateHandler implements PacketHandler { + + private static final Logger LOGGER = LoggerFactory.getLogger(RequestAccountInactivateHandler.class); + + private final AmieClient amieClient; + + public RequestAccountInactivateHandler(AmieClient amieClient) { + this.amieClient = amieClient; + } + + @Override + public String supportsType() { + return "request_account_inactivate"; + } + + @Override + public void handle(JsonNode packetJson, PacketEntity packetEntity) { + LOGGER.info("Starting 'request_account_inactivate' handler for packet amie_id [{}].", packetEntity.getAmieId()); + + JsonNode body = packetJson.path("body"); + String projectId = body.path("ProjectID").asText(); + String personId = body.path("PersonID").asText(); + + Assert.hasText(projectId, "'ProjectID' must not be empty."); + Assert.hasText(personId, "'PersonID' must not be empty."); + LOGGER.info("Packet validated. Inactivating account for user [{}] on project [{}].", personId, projectId); + + // TODO - perform the business logic + // - find the user's project record and mark it as inactive + // - remove the user from project's Slurm account + LOGGER.info("Simulating business logic: Removing user [{}] from project [{}]'s allocation.", personId, projectId); + + + // Send the 'notify_account_inactivate' reply. + Map<String, Object> replyBody = new HashMap<>(); + Map<String, Object> bodyContent = new HashMap<>(); + + bodyContent.put("ProjectID", projectId); + bodyContent.put("PersonID", personId); + + List<String> resourceList = new ArrayList<>(); + JsonNode rlNode = body.path("ResourceList"); + if (rlNode.isArray()) { + rlNode.forEach(node -> resourceList.add(node.asText())); + } + bodyContent.put("ResourceList", resourceList); + + replyBody.put("type", "notify_account_inactivate"); + replyBody.put("body", bodyContent); + + amieClient.replyToPacket(packetEntity.getAmieId(), replyBody); + + LOGGER.info("Successfully completed 'request_account_inactivate' handler and sent reply for packet amie_id [{}].", packetEntity.getAmieId()); + } +} diff --git a/amie-decoder/src/main/java/org/apache/custos/amie/handler/RequestProjectReactivateHandler.java b/amie-decoder/src/main/java/org/apache/custos/amie/handler/RequestProjectReactivateHandler.java new file mode 100644 index 000000000..325d2975b --- /dev/null +++ b/amie-decoder/src/main/java/org/apache/custos/amie/handler/RequestProjectReactivateHandler.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.custos.amie.handler; + +import com.fasterxml.jackson.databind.JsonNode; +import org.apache.custos.amie.client.AmieClient; +import org.apache.custos.amie.model.PacketEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import org.springframework.util.Assert; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Handles the 'request_project_reactivate' AMIE packet. + * <p> + * This transaction asks the local site to reactivate a project that was previously inactivated. + * This should only reactivate the PI's account on the project and send a 'notify_project_reactivate' reply upon completion. + */ +@Component +public class RequestProjectReactivateHandler implements PacketHandler { + + private static final Logger LOGGER = LoggerFactory.getLogger(RequestProjectReactivateHandler.class); + + private final AmieClient amieClient; + + public RequestProjectReactivateHandler(AmieClient amieClient) { + this.amieClient = amieClient; + } + + @Override + public String supportsType() { + return "request_project_reactivate"; + } + + @Override + public void handle(JsonNode packetJson, PacketEntity packetEntity) { + LOGGER.info("Starting 'request_project_reactivate' handler for packet amie_id [{}].", packetEntity.getAmieId()); + + JsonNode body = packetJson.path("body"); + String projectId = body.path("ProjectID").asText(); + String personId = body.path("PersonID").asText(); + + Assert.hasText(projectId, "'ProjectID' must not be empty."); + Assert.hasText(personId, "'PersonID' must not be empty."); + LOGGER.info("Packet validated. ProjectID to reactivate: [{}].", projectId); + + // TODO - perform the business logic + // - find the project by its local ID and activate it + // - find the PI's account (only this account) associated with this project and reactivate it + LOGGER.info("Simulating business logic: Marking project [{}] as active and reactivating the PI's ({}) account link.", projectId, personId); + + // Send the 'notify_project_reactivate' reply. + Map<String, Object> replyBody = new HashMap<>(); + Map<String, Object> bodyContent = new HashMap<>(); + + bodyContent.put("ProjectID", projectId); + bodyContent.put("PersonID", personId); + + List<String> resourceList = new ArrayList<>(); + JsonNode rlNode = body.path("ResourceList"); + if (rlNode.isArray()) { + rlNode.forEach(node -> resourceList.add(node.asText())); + } + bodyContent.put("ResourceList", resourceList); + + replyBody.put("type", "notify_project_reactivate"); + replyBody.put("body", bodyContent); + + amieClient.replyToPacket(packetEntity.getAmieId(), replyBody); + + LOGGER.info("Successfully completed 'request_project_reactivate' handler and sent reply for packet amie_id [{}].", packetEntity.getAmieId()); + } +}
