Skip to content

Commit

Permalink
dnchoe: Wrapping with trycatch for API #158
Browse files Browse the repository at this point in the history
  • Loading branch information
Choe DaeBeom committed May 21, 2020
1 parent 4cb964c commit 4b5475e
Show file tree
Hide file tree
Showing 4 changed files with 645 additions and 489 deletions.
130 changes: 71 additions & 59 deletions frontend/src/agent_admin/containers/AgentConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export class AgentConfiguration extends PureComponent<
})
}

public onClickTableRowCall = async (host: string, ip: string) => {
public onClickTableRowCall = (host: string, ip: string) => {
if (this.state.focusedHost === host) return
const {
notify,
Expand All @@ -376,59 +376,69 @@ export class AgentConfiguration extends PureComponent<
host
)

getLocalFileReadPromise.then(({data}) => {
const hostData = data.return[0][host]
const hostLocalFileReadData = hostData.substring(
0,
hostData.lastIndexOf('\n')
)
const configObj = TOML.parse(hostLocalFileReadData)
const agent: any = _.get(configObj, 'agent')
getLocalFileReadPromise
.then(({data}) => {
const hostData = data.return[0][host]
const hostLocalFileReadData = hostData.substring(
0,
hostData.lastIndexOf('\n')
)
const configObj = TOML.parse(hostLocalFileReadData)
const agent: any = _.get(configObj, 'agent')

let isChanged = false
let isChanged = false

if (agent.hostname !== host) {
notify(notifyAgentConfigHostNameChanged(agent.hostname, host))
_.set(agent, 'hostname', host)
isChanged = true
}
if (agent.hostname !== host) {
notify(notifyAgentConfigHostNameChanged(agent.hostname, host))
_.set(agent, 'hostname', host)
isChanged = true
}

this.setState({
configScript: TOML.stringify(configObj),
isGetLocalStorage: isChanged,
isApplyBtnDisabled: isChanged ? !isChanged : true,
collectorConfigStatus: RemoteDataState.Done,
configPageStatus: RemoteDataState.Done,
selectedOrg: this.DEFAULT_DROPDOWN_TEXT,
this.setState({
configScript: TOML.stringify(configObj),
isGetLocalStorage: isChanged,
isApplyBtnDisabled: isChanged ? !isChanged : true,
collectorConfigStatus: RemoteDataState.Done,
configPageStatus: RemoteDataState.Done,
selectedOrg: this.DEFAULT_DROPDOWN_TEXT,
})
})
.catch(error => {
console.error(error)
})
})

const getLocalServiceGetRunningPromise = getLocalServiceGetRunning(
saltMasterUrl,
saltMasterToken,
host
)

getLocalServiceGetRunningPromise.then(({data}) => {
const {defaultService} = this.state
const getServiceRunning = defaultService
.filter(m => data.return[0][host].includes(m))
.map(sMeasure => ({
name: sMeasure,
isActivity: false,
}))

const getDefaultMeasure = this.defaultMeasurementsData.map(dMeasure => ({
name: dMeasure,
isActivity: false,
}))
getLocalServiceGetRunningPromise
.then(({data}) => {
const {defaultService} = this.state
const getServiceRunning = defaultService
.filter(m => data.return[0][host].includes(m))
.map(sMeasure => ({
name: sMeasure,
isActivity: false,
}))

this.setState({
serviceMeasurements: getServiceRunning,
defaultMeasurements: getDefaultMeasure,
measurementsStatus: RemoteDataState.Done,
const getDefaultMeasure = this.defaultMeasurementsData.map(
dMeasure => ({
name: dMeasure,
isActivity: false,
})
)

this.setState({
serviceMeasurements: getServiceRunning,
defaultMeasurements: getDefaultMeasure,
measurementsStatus: RemoteDataState.Done,
})
})
.catch(error => {
console.error(error)
})
})
}

public onClickActionCall = async (host: string, isRunning: boolean) => {
Expand Down Expand Up @@ -763,7 +773,7 @@ export class AgentConfiguration extends PureComponent<
)
}

private handleFocusedServiceMeasure = ({
private handleFocusedServiceMeasure = async ({
clickPosition,
_thisProps,
}: {
Expand Down Expand Up @@ -801,24 +811,25 @@ export class AgentConfiguration extends PureComponent<
? (serviceMeasurements[idx].isActivity = true)
: (serviceMeasurements[idx].isActivity = false)

const getRunnerSaltCmdTelegrafPromise = getRunnerSaltCmdTelegraf(
saltMasterUrl,
saltMasterToken,
measureName
)

getRunnerSaltCmdTelegrafPromise.then(({data}) => {
try {
const {data} = await getRunnerSaltCmdTelegraf(
saltMasterUrl,
saltMasterToken,
measureName
)
this.setState({
serviceMeasurements: [...mapServiceMeasurements],
defaultMeasurements: [...mapDefaultMeasurements],
focusedMeasure: measureName,
focusedMeasurePosition: clickPosition,
description: data.return[0],
})
})
} catch (error) {
console.error(error)
}
}

private handleFocusedDefaultMeasure = ({
private handleFocusedDefaultMeasure = async ({
clickPosition,
_thisProps,
}: {
Expand Down Expand Up @@ -856,21 +867,22 @@ export class AgentConfiguration extends PureComponent<
description: globalSetting,
})
} else {
const getRunnerSaltCmdTelegrafPromise = getRunnerSaltCmdTelegraf(
saltMasterUrl,
saltMasterToken,
name
)

getRunnerSaltCmdTelegrafPromise.then(({data}) => {
try {
const {data} = await getRunnerSaltCmdTelegraf(
saltMasterUrl,
saltMasterToken,
name
)
this.setState({
defaultMeasurements: [...mapDefaultMeasurements],
serviceMeasurements: [...mapServiceMeasurements],
focusedMeasure: name,
focusedMeasurePosition: clickPosition,
description: data.return[0],
})
})
} catch (error) {
console.error(error)
}
}
}

Expand Down
Loading

0 comments on commit 4b5475e

Please sign in to comment.