Ejemplo n.º 1
0
func DeleteService(svcId string) error {
	// in case of failure
	oldService, err := database.GetService(svcId)
	if err != nil {
		if !strings.Contains(err.Error(), "No Service Found") {
			return err
		}
	}

	// delete backend rule
	err = balance.DeleteService(svcId)
	if err != nil {
		return err
	}

	if !database.CentralStore {
		// remove from backend
		err = database.DeleteService(svcId)
		if err != nil {
			// undo balance action
			if oldService != nil {
				if uerr := balance.SetService(oldService); uerr != nil {
					err = fmt.Errorf("%v - %v", err.Error(), uerr.Error())
				}
			}
			return err
		}
	}
	return nil
}
Ejemplo n.º 2
0
func TestDeleteService(t *testing.T) {
	if err := database.DeleteService(testService2.Id); err != nil {
		t.Errorf("Failed to DELETE service - %v", err)
	}

	if _, err := os.Stat("/tmp/scribbleTest/services/tcp-192_168_0_16-80.json"); !os.IsNotExist(err) {
		t.Errorf("Failed to DELETE service - %v", err)
	}
}
Ejemplo n.º 3
0
func (n None) DeleteService(id string) error {
	err := common.DeleteService(id)
	if err != nil {
		return err
	}
	if database.CentralStore {
		return database.DeleteService(id)
	}
	return nil
}
Ejemplo n.º 4
0
// DeleteService tells all members to remove the service from their database.
// rolls back on failure
func (r *Redis) DeleteService(id string) error {
	conn := pool.Get()
	defer conn.Close()

	oldService, err := common.GetService(id)
	// this should not return nil to ensure the service is gone from entire cluster
	if err != nil && !strings.Contains(err.Error(), "No Service Found") {
		return err
	}

	// publishString to others
	err = r.publishString(conn, "delete-service", id)
	if err != nil {
		// if i failed to publishString, request should fail
		return err
	}

	actionHash := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("delete-service %s", id))))

	// ensure all members applied action
	err = r.waitForMembers(conn, actionHash)
	if err != nil {
		uActionHash := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("set-service %s", oldService))))
		// cleanup rollback cruft. clear actionHash ensures no mistakes on re-submit
		defer conn.Do("DEL", uActionHash, actionHash)
		// attempt rollback - no need to waitForMembers here
		uerr := r.publishJson(conn, "set-service", oldService)
		if uerr != nil {
			err = fmt.Errorf("%v - %v", err, uerr)
		}
		return err
	}

	if database.CentralStore {
		return database.DeleteService(id)
	}

	return nil
}