/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed 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. */ import React, { useState, useEffect } from "react"; import ArrowDropDownIcon from "@material-ui/icons/ArrowDropDown"; import PagePanel from "components/PagePanel"; import HeaderPanel from "components/HeaderPanel"; import FormItem from "components/FormItem"; import TextInput from "components/TextInput"; import ExtLink from "components/ExtLink"; import { appSyncRequestQuery } from "assets/js/request"; import { getDomainDetails, listImportedDomains } from "graphql/queries"; import { SelectItem } from "components/Select/select"; import { DomainDetails, ImportedDomain } from "API"; import Select from "components/Select"; import { ApplicationLogType } from "../CreatePipeline"; import { ENABLE_CLODSTATE, ENABLE_ULTRAWARM, PIPELINE_TASK_ES_USER_DEFAULT, REPLICA_COUNT_LIST, } from "assets/js/const"; import { InfoBarTypes } from "reducer/appReducer"; import { useTranslation } from "react-i18next"; import Switch from "components/Switch"; import { ClusterCompressionTypeList, AppLogClusterIndexSuffixFormatList, WarmLogSettingsList, WarmTransitionType, } from "types"; interface SpecifyOpenSearchClusterProps { applicationLog: ApplicationLogType; changeOpenSearchCluster: (domain: DomainDetails | undefined) => void; changeWarnLogTransition: (value: string) => void; changeColdLogTransition: (value: string) => void; changeLogRetention: (value: string) => void; changeLoadingDomain: (loading: boolean) => void; changeShards: (shards: string) => void; changeReplicas: (replica: string) => void; changeIndexSuffix: (suffix: string) => void; changeEnableRollover: (enable: boolean) => void; changeRolloverSize: (size: string) => void; changeCompressionType: (codec: string) => void; changeWarmSettings: (type: string) => void; esDomainEmptyError: boolean; warmLogInvalidError?: boolean; coldLogInvalidError?: boolean; logRetentionInvalidError?: boolean; coldMustLargeThanWarm?: boolean; logRetentionMustThanColdAndWarm?: boolean; shardsInvalidError?: boolean; rolloverSizeError?: boolean; } const SpecifyOpenSearchCluster: React.FC = ( props: SpecifyOpenSearchClusterProps ) => { const { applicationLog, changeOpenSearchCluster, changeWarnLogTransition, changeColdLogTransition, changeLogRetention, changeLoadingDomain, changeShards, changeReplicas, changeIndexSuffix, changeEnableRollover, changeRolloverSize, changeCompressionType, changeWarmSettings, esDomainEmptyError, warmLogInvalidError, coldLogInvalidError, logRetentionInvalidError, coldMustLargeThanWarm, logRetentionMustThanColdAndWarm, shardsInvalidError, rolloverSizeError, } = props; const { t } = useTranslation(); const [loadingDomain, setLoadingDomain] = useState(false); const [openSearchCluster, setOpenSearchCuster] = useState( applicationLog.openSearchId ); const [domainOptionList, setDomainOptionList] = useState([]); const [showAdvanceSetting, setShowAdvanceSetting] = useState(false); const getImportedESDomainList = async () => { try { setLoadingDomain(true); changeLoadingDomain(true); const resData: any = await appSyncRequestQuery(listImportedDomains); const dataDomains: ImportedDomain[] = resData.data.listImportedDomains; const tmpDomainList: SelectItem[] = []; const userDefaultES: string = localStorage.getItem(PIPELINE_TASK_ES_USER_DEFAULT) || ""; const tmpESIdList: string[] = []; dataDomains.forEach((element) => { tmpESIdList.push(element.id); tmpDomainList.push({ name: element.domainName, value: element.id, }); // tmpDomainMap[element.domainName] = element; }); setDomainOptionList(tmpDomainList); // select user default cluster when multiple es if (tmpESIdList.includes(userDefaultES)) { setOpenSearchCuster(userDefaultES); } else { // select the only one es item if (tmpDomainList.length === 1) { setOpenSearchCuster(tmpDomainList[0].value); } } setLoadingDomain(false); changeLoadingDomain(false); } catch (error) { console.error(error); changeLoadingDomain(false); } }; useEffect(() => { getImportedESDomainList(); }, []); const esSelectChanged = async (cluster: string) => { const resData: any = await appSyncRequestQuery(getDomainDetails, { id: cluster, }); console.info("resData:", resData); const dataDomain: DomainDetails = resData.data.getDomainDetails; changeOpenSearchCluster(dataDomain); }; useEffect(() => { console.info("openSearchCluster:", openSearchCluster); if (openSearchCluster) { esSelectChanged(openSearchCluster); localStorage.setItem(PIPELINE_TASK_ES_USER_DEFAULT, openSearchCluster); } }, [openSearchCluster]); return (
{t("applog:create.specifyOS.aosDomainDesc1")} {t("applog:create.specifyOS.aosDomainDesc2")} {t("applog:create.specifyOS.aosDomainDesc3")}
} errorText={ esDomainEmptyError ? t("applog:create.specifyOS.aosDomainError") : "" } > { changeIndexSuffix(event.target.value); }} />
{ changeShards(event.target.value); }} />
{ changeCompressionType(event.target.value); }} />
{t("servicelog:cluster.warmLogDesc1")} {t("servicelog:cluster.warmLogDesc2")} {t("servicelog:cluster.warmLogDesc3")}
} errorText={ warmLogInvalidError ? t("applog:create.specifyOS.warmLogInvalid") : "" } > <> {WarmLogSettingsList.map((element, key) => { return (
); })} { console.info(event.target.value); changeWarnLogTransition(event.target.value); }} />
{t("servicelog:cluster.coldLogDesc1")} {t("servicelog:cluster.coldLogDesc2")} {t("servicelog:cluster.coldLogDesc3")} } errorText={ coldLogInvalidError ? t("applog:create.specifyOS.coldLogInvalid") : coldMustLargeThanWarm ? t("applog:create.specifyOS.coldLogMustThanWarm") : "" } > { console.info(event.target.value); changeColdLogTransition(event.target.value); }} /> { console.info(event.target.value); changeLogRetention(event.target.value); }} /> ); }; export default SpecifyOpenSearchCluster;