(replicationID string, state string)
| 1155 | } |
| 1156 | |
| 1157 | func (m *sgReplicateManager) UpdateReplicationState(replicationID string, state string) error { |
| 1158 | |
| 1159 | updateReplicationStatusCallback := func(cluster *SGRCluster) (cancel bool, err error) { |
| 1160 | replicationCfg, exists := cluster.Replications[replicationID] |
| 1161 | if !exists { |
| 1162 | return true, base.ErrNotFound |
| 1163 | } |
| 1164 | |
| 1165 | stateChangeErr := isValidStateChange(replicationCfg.TargetState, state) |
| 1166 | if stateChangeErr != nil { |
| 1167 | return true, stateChangeErr |
| 1168 | } |
| 1169 | |
| 1170 | if state == ReplicationStateStopped && replicationCfg.Adhoc == true { |
| 1171 | delete(cluster.Replications, replicationID) |
| 1172 | cluster.RebalanceReplications() |
| 1173 | return false, nil |
| 1174 | } |
| 1175 | |
| 1176 | cluster.Replications[replicationID].TargetState = state |
| 1177 | cluster.RebalanceReplications() |
| 1178 | return false, nil |
| 1179 | } |
| 1180 | return m.updateCluster(updateReplicationStatusCallback) |
| 1181 | } |
| 1182 | |
| 1183 | func isValidStateChange(currentState, newState string) error { |
| 1184 |
no test coverage detected