Search in sources :

Example 1 with HistoryOperator

use of com.orion.ops.consts.history.HistoryOperator in project orion-ops by lijiahangmax.

the class HistoryValueServiceImpl method rollback.

@Override
public void rollback(Long id) {
    HistoryValueSnapshotDO historyValue = historyValueSnapshotDAO.selectById(id);
    Valid.notNull(historyValue, MessageConst.HISTORY_VALUE_ABSENT);
    // 设置修改值
    HistoryOperator operator = HistoryOperator.of(historyValue.getOperatorType());
    String updateValue;
    switch(operator) {
        case ADD:
            updateValue = historyValue.getAfterValue();
            break;
        case UPDATE:
        case DELETE:
        default:
            updateValue = historyValue.getBeforeValue();
    }
    // 修改值
    Long valueId = historyValue.getValueId();
    HistoryValueType valueType = HistoryValueType.of(historyValue.getValueType());
    switch(valueType) {
        case MACHINE_ENV:
            MachineEnvRequest machineEnvRequest = new MachineEnvRequest();
            machineEnvRequest.setId(valueId);
            machineEnvRequest.setValue(updateValue);
            machineEnvService.updateEnv(machineEnvRequest);
            return;
        case APP_ENV:
            ApplicationEnvRequest appEnvRequest = new ApplicationEnvRequest();
            appEnvRequest.setId(valueId);
            appEnvRequest.setValue(updateValue);
            applicationEnvService.updateAppEnv(appEnvRequest);
            return;
        case SYSTEM_ENV:
            SystemEnvRequest systemRequest = new SystemEnvRequest();
            systemRequest.setId(valueId);
            systemRequest.setValue(updateValue);
            systemEnvService.updateEnv(systemRequest);
            return;
        default:
    }
}
Also used : ApplicationEnvRequest(com.orion.ops.entity.request.ApplicationEnvRequest) MachineEnvRequest(com.orion.ops.entity.request.MachineEnvRequest) HistoryValueSnapshotDO(com.orion.ops.entity.domain.HistoryValueSnapshotDO) HistoryOperator(com.orion.ops.consts.history.HistoryOperator) SystemEnvRequest(com.orion.ops.entity.request.SystemEnvRequest) HistoryValueType(com.orion.ops.consts.history.HistoryValueType)

Aggregations

HistoryOperator (com.orion.ops.consts.history.HistoryOperator)1 HistoryValueType (com.orion.ops.consts.history.HistoryValueType)1 HistoryValueSnapshotDO (com.orion.ops.entity.domain.HistoryValueSnapshotDO)1 ApplicationEnvRequest (com.orion.ops.entity.request.ApplicationEnvRequest)1 MachineEnvRequest (com.orion.ops.entity.request.MachineEnvRequest)1 SystemEnvRequest (com.orion.ops.entity.request.SystemEnvRequest)1