Add implement for supporting replicatie the existing images now

This commit is contained in:
Wenkai Yin 2017-12-13 14:56:45 +08:00
parent b5e7de331e
commit c4dc95f4f9
2 changed files with 28 additions and 5 deletions

View File

@ -60,11 +60,16 @@ func (r *ReplicationAPI) Post() {
return
}
if err = notifier.Publish(topic.StartReplicationTopic, notification.StartReplicationNotification{
PolicyID: replication.PolicyID,
}); err != nil {
if err = startReplication(replication.PolicyID); err != nil {
r.HandleInternalServerError(fmt.Sprintf("failed to publish replication topic for policy %d: %v", replication.PolicyID, err))
return
}
log.Infof("replication topic for policy %d triggered", replication.PolicyID)
log.Infof("replication signal for policy %d sent", replication.PolicyID)
}
func startReplication(policyID int64) error {
return notifier.Publish(topic.StartReplicationTopic,
notification.StartReplicationNotification{
PolicyID: policyID,
})
}

View File

@ -145,7 +145,15 @@ func (pa *RepPolicyAPI) Post() {
return
}
// TODO trigger a replication if ReplicateExistingImageNow is true
if policy.ReplicateExistingImageNow {
go func() {
if err = startReplication(id); err != nil {
log.Errorf("failed to send replication signal for policy %d: %v", id, err)
return
}
log.Infof("replication signal for policy %d sent", id)
}()
}
pa.Redirect(http.StatusCreated, strconv.FormatInt(id, 10))
}
@ -201,6 +209,16 @@ func (pa *RepPolicyAPI) Put() {
pa.HandleInternalServerError(fmt.Sprintf("failed to update policy %d: %v", id, err))
return
}
if policy.ReplicateExistingImageNow {
go func() {
if err = startReplication(id); err != nil {
log.Errorf("failed to send replication signal for policy %d: %v", id, err)
return
}
log.Infof("replication signal for policy %d sent", id)
}()
}
}
// Delete the replication policy