Esempio n. 1
0
func (r *RPCRegistry) CreateUnit(j *job.Unit) error {
	if DebugRPCRegistry {
		defer debug.Exit_(debug.Enter_(j.Name))
	}

	un := j.ToPB()
	_, err := r.getClient().CreateUnit(r.ctx(), &un)
	return err
}
Esempio n. 2
0
func (rc *RegistryClient) CreateUnit(u *schema.Unit) error {
	rUnit := job.Unit{
		Name:        u.Name,
		Unit:        *schema.MapSchemaUnitOptionsToUnitFile(u.Options),
		TargetState: job.JobStateInactive,
	}

	if len(u.DesiredState) > 0 {
		ts, err := job.ParseJobState(u.DesiredState)
		if err != nil {
			return err
		}

		rUnit.TargetState = ts
	}

	return rc.Registry.CreateUnit(&rUnit)
}
Esempio n. 3
0
func UnitsCheck() check.ExtensionCheckResult {
	cl, err := NewFleetClient()

	if err != nil {
		return handler.Error(err.Error())
	}

	units, err := cl.Units()

	if err != nil {
		return handler.Error(err.Error())
	}

	wrongStates := []string{}

	for _, u := range units {
		if u.DesiredState != u.CurrentState || u.DesiredState == "inactive" {
			ju := job.Unit{Unit: *schema.MapSchemaUnitOptionsToUnitFile(u.Options)}

			if !ju.IsGlobal() {
				wrongStates = append(wrongStates, u.Name)
			}
		}
	}

	if len(wrongStates) == 0 {
		return handler.Ok("Every untis are in their desired states")
	} else {
		return handler.Error(
			fmt.Sprintf(
				"Units in an incoherent state: %s",
				strings.Join(wrongStates, ","),
			),
		)
	}
}
Esempio n. 4
0
// suToGlobal returns whether or not a schema.Unit refers to a global unit
func suToGlobal(su schema.Unit) bool {
	u := job.Unit{
		Unit: *schema.MapSchemaUnitOptionsToUnitFile(su.Options),
	}
	return u.IsGlobal()
}