// 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, getAppStates, updateArcControl} 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"; const ApplicationState: 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 { // 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")); // }); // // 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")); // }); // // 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); // }); // // 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); // }); // // getAppControls("settlement", "us-east-1").then( // (result: IAppControls) => { // console.log("Received Result for getAppControls for Settlement for Primary:" + JSON.stringify(result)) // setSettlementPrimaryControls(result); // }); // // getAppControls("settlement", "us-west-2").then( // (result: IAppControls) => { // console.log("Received Result for getAppControls for Settlement for Secondary:" + JSON.stringify(result)) // setSettlementSecondaryControls(result); // }); 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")); }); } catch (err) { // const items:FlashbarMessage[] = [ // { // header: 'Could not get the app state for Trade Matching: ' + err.toString(), // type: 'error', // dismissible: true, // } // ]; // setErrors(items); } try { 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")); }); } catch (err) { // const items:FlashbarMessage[] = [ // { // header: 'Could not get the app state for Settlement: ' + err.toString(), // type: 'error', // dismissible: true, // } // ]; // setErrors(items); } try { 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); }); } catch (err) { // const items:FlashbarMessage[] = [ // { // header: 'Could not get the app controls for Trade Matching for Primary: ' + err.toString(), // type: 'error', // dismissible: true, // } // ]; // setErrors(items); } try { 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); }); } catch (err) { // const items:FlashbarMessage[] = [ // { // header: 'Could not get the app controls for Trade Matching for Secondary: ' + err.toString(), // type: 'error', // dismissible: true, // } // ]; // setErrors(items); } try { 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); }); } catch (err) { // const items:FlashbarMessage[] = [ // { // header: 'Could not get the app controls for Settlement for Primary: ' + err.toString(), // type: 'error', // dismissible: true, // } // ]; // setErrors(items); } try { 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); }); } catch (err) { // const items:FlashbarMessage[] = [ // { // header: 'Could not get the app controls for Settlement for Secondary: ' + err.toString(), // type: 'error', // dismissible: true, // } // ]; // setErrors(items); } 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.")); }, 3000); return () => clearInterval(interval); }, []); const renderDNSControl = (state: any) => { return (state == "On"?:); } const renderQueueControl = (state: any) => { return (state == "On"?:); } const renderAppControl = (state: any) => { return (state == "On"?:); } return (
Trade Generator                  
Trade Matching                  
Settlement                  
Primary (US East 1)
Trade Matching
{renderDNSControl(tradeMatchingPrimaryControls.dns_arc_control_state?tradeMatchingPrimaryControls.dns_arc_control_state:"Off")}
{renderQueueControl(tradeMatchingPrimaryControls.queue_arc_control_state?tradeMatchingPrimaryControls.queue_arc_control_state:"Off")}
{renderAppControl(tradeMatchingPrimaryControls.app_arc_control_state?tradeMatchingPrimaryControls.app_arc_control_state:"Off")}
Inbound Gateway
Trades: {tradeMatchingPrimaryState.inbound_gateway_trade_store_count?tradeMatchingPrimaryState.inbound_gateway_trade_store_count:0}
Settlements: {tradeMatchingPrimaryState.inbound_gateway_settlement_store_count?tradeMatchingPrimaryState.inbound_gateway_settlement_store_count:0}
Ingestion
Trades: {tradeMatchingPrimaryState.ingestion_trade_store_count?tradeMatchingPrimaryState.ingestion_trade_store_count:0}
Settlements: {tradeMatchingPrimaryState.ingestion_settlement_store_count?tradeMatchingPrimaryState.ingestion_settlement_store_count:0}
Matching
Total: {tradeMatchingPrimaryState.matching_store_count?tradeMatchingPrimaryState.matching_store_count:0}
Settled: {tradeMatchingPrimaryState.matching_settled_store_count?tradeMatchingPrimaryState.matching_settled_store_count:0}
Matched: {tradeMatchingPrimaryState.matching_matched_store_count?tradeMatchingPrimaryState.matching_matched_store_count:0}
Mismatched: {tradeMatchingPrimaryState.matching_mismatched_store_count?tradeMatchingPrimaryState.matching_mismatched_store_count:0}
Unmatched: {tradeMatchingPrimaryState.matching_unmatched_store_count?tradeMatchingPrimaryState.matching_unmatched_store_count:0}
Egress
Trades: {tradeMatchingPrimaryState.egress_trade_store_count?tradeMatchingPrimaryState.egress_trade_store_count:0}
Settlements: {tradeMatchingPrimaryState.egress_settlement_store_count?tradeMatchingPrimaryState.egress_settlement_store_count:0}
Outbound Gateway
Trades: {tradeMatchingPrimaryState.outbound_gateway_trade_store_count?tradeMatchingPrimaryState.outbound_gateway_trade_store_count:0}
Settlements: {tradeMatchingPrimaryState.outbound_gateway_settlement_store_count?tradeMatchingPrimaryState.outbound_gateway_settlement_store_count:0}
Settlement
{renderDNSControl(settlementPrimaryControls.dns_arc_control_state?settlementPrimaryControls.dns_arc_control_state:"Off")}
{renderQueueControl(settlementPrimaryControls.queue_arc_control_state?settlementPrimaryControls.queue_arc_control_state:"Off")}
{renderAppControl(settlementPrimaryControls.app_arc_control_state?settlementPrimaryControls.app_arc_control_state:"Off")}
Inbound Gateway
Settlements: {settlementPrimaryState.inbound_gateway_settlement_store_count?settlementPrimaryState.inbound_gateway_settlement_store_count:0}
Ingestion
Settlements: {settlementPrimaryState.ingestion_settlement_store_count?settlementPrimaryState.ingestion_settlement_store_count:0}
Matching
Total: {settlementPrimaryState.matching_store_count?settlementPrimaryState.matching_store_count:0}
Matched: {settlementPrimaryState.matching_matched_store_count?settlementPrimaryState.matching_matched_store_count:0}
Mismatched: {settlementPrimaryState.matching_mismatched_store_count?settlementPrimaryState.matching_mismatched_store_count:0}
Unmatched: {settlementPrimaryState.matching_unmatched_store_count?settlementPrimaryState.matching_unmatched_store_count:0}
Egress
Settlements: {settlementPrimaryState.egress_settlement_store_count?settlementPrimaryState.egress_settlement_store_count:0}
Outbound Gateway
Settlements: {settlementPrimaryState.outbound_gateway_settlement_store_count?settlementPrimaryState.outbound_gateway_settlement_store_count:0}
Secondary (US West 2)
Trade Matching
{renderDNSControl(tradeMatchingSecondaryControls.dns_arc_control_state?tradeMatchingSecondaryControls.dns_arc_control_state:"Off")}
{renderQueueControl(tradeMatchingSecondaryControls.queue_arc_control_state?tradeMatchingSecondaryControls.queue_arc_control_state:"Off")}
{renderAppControl(tradeMatchingSecondaryControls.app_arc_control_state?tradeMatchingSecondaryControls.app_arc_control_state:"Off")}
Inbound Gateway
Trades: {tradeMatchingSecondaryState.inbound_gateway_trade_store_count?tradeMatchingSecondaryState.inbound_gateway_trade_store_count:0}
Settlements: {tradeMatchingSecondaryState.inbound_gateway_settlement_store_count?tradeMatchingSecondaryState.inbound_gateway_settlement_store_count:0}
Ingestion
Trades: {tradeMatchingSecondaryState.ingestion_trade_store_count?tradeMatchingSecondaryState.ingestion_trade_store_count:0}
Settlements: {tradeMatchingSecondaryState.ingestion_settlement_store_count?tradeMatchingSecondaryState.ingestion_settlement_store_count:0}
Matching
Total: {tradeMatchingSecondaryState.matching_store_count?tradeMatchingSecondaryState.matching_store_count:0}
Settled: {tradeMatchingSecondaryState.matching_settled_store_count?tradeMatchingSecondaryState.matching_settled_store_count:0}
Matched: {tradeMatchingSecondaryState.matching_matched_store_count?tradeMatchingSecondaryState.matching_matched_store_count:0}
Mismatched: {tradeMatchingSecondaryState.matching_mismatched_store_count?tradeMatchingSecondaryState.matching_mismatched_store_count:0}
Unmatched: {tradeMatchingSecondaryState.matching_unmatched_store_count?tradeMatchingSecondaryState.matching_unmatched_store_count:0}
Egress
Trades: {tradeMatchingSecondaryState.egress_trade_store_count?tradeMatchingSecondaryState.egress_trade_store_count:0}
Settlements: {tradeMatchingSecondaryState.egress_settlement_store_count?tradeMatchingSecondaryState.egress_settlement_store_count:0}
Outbound Gateway
Trades: {tradeMatchingSecondaryState.outbound_gateway_trade_store_count?tradeMatchingSecondaryState.outbound_gateway_trade_store_count:0}
Settlements: {tradeMatchingSecondaryState.outbound_gateway_settlement_store_count?tradeMatchingSecondaryState.outbound_gateway_settlement_store_count:0}
Settlement
{renderDNSControl(settlementSecondaryControls.dns_arc_control_state?settlementSecondaryControls.dns_arc_control_state:"Off")}
{renderQueueControl(settlementSecondaryControls.queue_arc_control_state?settlementSecondaryControls.queue_arc_control_state:"Off")}
{renderAppControl(settlementSecondaryControls.app_arc_control_state?settlementSecondaryControls.app_arc_control_state:"Off")}
Inbound Gateway
Settlements: {settlementSecondaryState.inbound_gateway_settlement_store_count?settlementSecondaryState.inbound_gateway_settlement_store_count:0}
Ingestion
Settlements: {settlementSecondaryState.ingestion_settlement_store_count?settlementSecondaryState.ingestion_settlement_store_count:0}
Matching
Total: {settlementSecondaryState.matching_store_count?settlementSecondaryState.matching_store_count:0}
Matched: {settlementSecondaryState.matching_matched_store_count?settlementSecondaryState.matching_matched_store_count:0}
Mismatched: {settlementSecondaryState.matching_mismatched_store_count?settlementSecondaryState.matching_mismatched_store_count:0}
Unmatched: {settlementSecondaryState.matching_unmatched_store_count?settlementSecondaryState.matching_unmatched_store_count:0}
Egress
Settlements: {settlementSecondaryState.egress_settlement_store_count?settlementSecondaryState.egress_settlement_store_count:0}
Outbound Gateway
Settlements: {settlementSecondaryState.outbound_gateway_settlement_store_count?settlementSecondaryState.outbound_gateway_settlement_store_count:0}
{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 ApplicationState;