// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT-0 import React, {FunctionComponent, useEffect, useState} from 'react'; import {Container, Button} from "aws-northstar"; import Stack from "aws-northstar/layouts/Stack"; import '../home/styles.css'; import {IAppControls, IAppState} from "../../interfaces"; import {useHistory} from "react-router-dom"; import Grid from "aws-northstar/esm/layouts/Grid"; import { executeRunbook, getAppControls, getAppState, getAppStates, updateArcControl, cleanDatabases, startApplication, stopApplications } from "../../data"; import Flashbar, {FlashbarMessage} from "aws-northstar/components/Flashbar"; import Alert from "aws-northstar/components/Alert"; import dns_on from "./dns_on.png"; import dns_off from "./dns_off.png"; import queue_on from "./queue_on.png"; import queue_off from "./queue_off.png"; import app_on from "./app_on.png"; import app_off from "./app_off.png"; import TEA from "../home/TEA.png"; const ApplicationAdmin: FunctionComponent = () => { const history = useHistory(); const [tradeMatchingPrimaryState, setTradeMatchingPrimaryState] = useState({}); const [tradeMatchingSecondaryState, setTradeMatchingSecondaryState] = useState({}); const [settlementPrimaryState, setSettlementPrimaryState] = useState({}); const [settlementSecondaryState, setSettlementSecondaryState] = useState({}); const [tradeMatchingPrimaryControls, setTradeMatchingPrimaryControls] = useState({}); const [tradeMatchingSecondaryControls, setTradeMatchingSecondaryControls] = useState({}); const [settlementPrimaryControls, setSettlementPrimaryControls] = useState({}); const [settlementSecondaryControls, setSettlementSecondaryControls] = useState({}); const [errors, setErrors] = React.useState([]); const [message, setMessage] = React.useState(""); const startTradeGenerator = async () => { setMessage("Initiated Trade Generator Start") let request = await updateArcControl("trade-matching", "generator", "", "On").then( (result: any) => { console.log("Received Result :" + JSON.stringify(result)) }); } const stopTradeGenerator = async () => { setMessage("Initiated Trade Generator Stop") let request = await updateArcControl("trade-matching", "generator", "", "Off").then( (result: any) => { console.log("Received Result :" + JSON.stringify(result)) }); } const rotateTradeMatching = async () => { setMessage("Initiated Trade Matching App Rotation") let request = await executeRunbook("us-east-1", "approtation-Runbook-Managed-Failover", "trade-matching", "App Rotation", "test", "Off").then( (result: any) => { console.log("Received Result :" + JSON.stringify(result)) }); } const drTradeMatching = async () => { setMessage("Initiated Trade Matching DR") let request = await executeRunbook("us-east-1", "approtation-Runbook-Detach-And-Promote", "trade-matching", "DR", "test", "Off").then( (result: any) => { console.log("Received Result :" + JSON.stringify(result)) }); } const rotateSettlement = async () => { setMessage("Initiated Settlement App Rotation") let request = await executeRunbook("us-east-1", "approtation-Runbook-Managed-Failover", "settlement", "App Rotation", "test", "Off").then( (result: any) => { console.log("Received Result :" + JSON.stringify(result)) }); } const drSettlement = async () => { setMessage("Initiated Settlement App Rotation") let request = await executeRunbook("us-east-1", "approtation-Runbook-Detach-And-Promote", "settlement", "DR", "test", "Off").then( (result: any) => { console.log("Received Result :" + JSON.stringify(result)) }); } const renderMessage = () => { return (message == ""?
: setMessage("")} > {message} ); } const getAllRequests = async () => { try { let request1 = await getAppStates("trade-matching").then( (result: IAppState[]) => { console.log("Received Result for getAppState for Trade Matching:" + JSON.stringify(result)) setTradeMatchingPrimaryState(get_app_state(result, "trade-matching", "us-east-1")); setTradeMatchingSecondaryState(get_app_state(result, "trade-matching", "us-west-2")); }); let request2 = await getAppStates("settlement").then( (result: IAppState[]) => { console.log("Received Result for getAppState for Settlement" + JSON.stringify(result)) setSettlementPrimaryState(get_app_state(result, "settlement", "us-east-1")); setSettlementSecondaryState(get_app_state(result, "settlement", "us-west-2")); }); let request3 = await getAppControls("trade-matching", "us-east-1").then( (result: IAppControls) => { console.log("Received Result for getAppControls for Trade Matching for Primary:" + JSON.stringify(result)) setTradeMatchingPrimaryControls(result); }); let request4 = await getAppControls("trade-matching", "us-west-2").then( (result: IAppControls) => { console.log("Received Result for getAppControls for Trade Matching for Secondary:" + JSON.stringify(result)) setTradeMatchingSecondaryControls(result); }); let request5 = await getAppControls("settlement", "us-east-1").then( (result: IAppControls) => { console.log("Received Result for getAppControls for Settlement for Primary:" + JSON.stringify(result)) setSettlementPrimaryControls(result); }); let request6 = await getAppControls("settlement", "us-west-2").then( (result: IAppControls) => { console.log("Received Result for getAppControls for Settlement for Secondary:" + JSON.stringify(result)) setSettlementSecondaryControls(result); }); await Promise.resolve(); } catch (err) { const items:FlashbarMessage[] = [ { header: 'Could not get the app state: ' + err.toString(), type: 'error', dismissible: true, } ]; setErrors(items); } } // const getAllRequests = async () => { // // try { // // let request1 = await getAppState("trade-matching", "us-east-1").then( // (result: IAppState) => { // console.log("Received Result :" + JSON.stringify(result)) // setTradeMatchingPrimaryState(result); // }); // // let request2 = await getAppState("trade-matching", "us-west-2").then( // (result: IAppState) => { // console.log("Received Result :" + JSON.stringify(result)) // setTradeMatchingSecondaryState(result); // }); // // let request3 = await getAppState("settlement", "us-east-1").then( // (result: IAppState) => { // console.log("Received Result :" + JSON.stringify(result)) // setSettlementPrimaryState(result); // }); // // let request4 = await getAppState("settlement", "us-west-2").then( // (result: IAppState) => { // console.log("Received Result :" + JSON.stringify(result)) // setSettlementSecondaryState(result); // }); // // await Promise.resolve(); // // } // catch (err) { // const items:FlashbarMessage[] = [ // { // header: 'Could not get the app state: ' + err.toString(), // type: 'error', // dismissible: true, // } // ]; // setErrors(items); // } // } useEffect( () => { console.log("useEffect Called") // getAllRequests().then(() => console.log("getAppState() completed.")); // const interval = setInterval(() => { // getAllRequests().then(() => console.log("getAppState() completed.")); // }, 1000); // return () => clearInterval(interval); }, []); const renderDNSControl = (state: any) => { return (state == "On"?:); } const renderQueueControl = (state: any) => { return (state == "On"?:); } const renderAppControl = (state: any) => { return (state == "On"?:); } const startTradeMatchingPrimary = async () => { setMessage("Initiated Start Trade Matching Application in Primary") let request = await startApplication("trade", "us-east-1").then( (result: any) => { console.log("Received Result :" + JSON.stringify(result)) }); } const startTradeMatchingSecondary = async () => { setMessage("Initiated Start Trade Matching Application in Secondary") let request = await startApplication("trade", "us-west-2").then( (result: any) => { console.log("Received Result :" + JSON.stringify(result)) }); } const startSettlementPrimary = async () => { setMessage("Initiated Start Settlement Application in Primary") let request = await startApplication("settlement", "us-east-1").then( (result: any) => { console.log("Received Result :" + JSON.stringify(result)) }); } const startSettlementSecondary = async () => { setMessage("Initiated Start Settlement Application in Secondary") let request = await startApplication("settlement", "us-west-2").then( (result: any) => { console.log("Received Result :" + JSON.stringify(result)) }); } const stopApplicationsPrimary = async () => { setMessage("Initiated Stop Applications in Primary") let request = await stopApplications("us-east-1").then( (result: any) => { console.log("Received Result :" + JSON.stringify(result)) }); } const stopApplicationsSecondary = async () => { setMessage("Initiated Stop Applications in Secondary") let request = await stopApplications("us-west-2").then( (result: any) => { console.log("Received Result :" + JSON.stringify(result)) }); } const clearDatabases = async () => { setMessage("Initiated Clean Databases") let request = await cleanDatabases().then( (result: any) => { console.log("Received Result :" + JSON.stringify(result)) }); } return (
Both Applications                           
Trade Matching                  
Settlement                  
{renderMessage()}
); } function get_app_state(apps: any, app_name: any, app_region: any) { for (var app of apps) { if ((app.app_name == app_name) && (app.app_region == app_region)) { // var app_state:IAppState = { // app_name = app.app_name, // app_region = app.app_region, // inbound_gateway_trade_store_count = app.inbound_gateway_trade_store_count, // inbound_gateway_settlement_store_count = app.inbound_gateway_settlement_store_count, // ingestion_trade_store_count = app.ingestion_trade_store_count, // ingestion_settlement_store_count = app.ingestion_settlement_store_count, // matching_store_count = app.matching_store_count, // matching_unmatched_store_count = app.matching_unmatched_store_count, // matching_matched_store_count = app.matching_matched_store_count, // matching_mismatched_store_count = app.matching_mismatched_store_count, // egress_trade_store_count = app.egress_trade_store_count, // egress_settlement_store_count = app.egress_settlement_store_count, // outbound_gateway_trade_store_count = app.outbound_gateway_trade_store_count, // outbound_gateway_settlement_store_count = app.outbound_gateway_settlement_store_count // }; return app } } return {}; } export default ApplicationAdmin;