Example #1
0
// Drop service.
func (s *SessionHandler) dropServiceHandler(tokens []string) iface.IResponse {
	if len(tokens) == 0 {
		return common.InvalidRequest("Service name must be provided")
	}
	if len(tokens) > 1 {
		return common.InvalidRequest("DROP accept service name only")
	}
	svcName := tokens[0]
	res := s.svcs.DropService(svcName)
	return res
}
Example #2
0
// GetServiceConfig reads service config bases on service name.
// Caller should provide correct settings structure to read binary data.
func (ds *DataStorage) LoadServiceConfig(conf iface.Marshalable, serviceId string) error {
	key := makeSettingsKey(serviceId)
	data, _ := ds.db.Get(defaultReadOptions, key)
	if data == nil {
		return common.InvalidRequest("No service settings found: " + serviceId)
	}

	if err := conf.Unmarshal(data); err != nil {
		log.Error("Error in '%s' service settings: %s", serviceId, err.Error())
		return common.InvalidRequest("Service settings error: " + serviceId)
	}
	return nil
}
Example #3
0
// Call dispatches processing of the command to the appropriate command parser.
func (pq *PQueue) Call(cmd string, params []string) iface.IResponse {
	switch cmd {
	case ACTION_POP_WAIT:
		return pq.PopWait(params)
	case ACTION_DELETE_LOCKED_BY_ID:
		return pq.DeleteLockedById(params)
	case ACTION_DELETE_BY_ID:
		return pq.DeleteById(params)
	case ACTION_POP:
		return pq.Pop(params)
	case ACTION_PUSH:
		return pq.Push(params)
	case ACTION_SET_LOCK_TIMEOUT:
		return pq.SetLockTimeout(params)
	case ACTION_UNLOCK_BY_ID:
		return pq.UnlockMessageById(params)
	case ACTION_STATUS:
		return pq.GetCurrentStatus(params)
	case ACTION_RELEASE_IN_FLIGHT:
		return pq.ReleaseInFlight(params)
	case ACTION_EXPIRE:
		return pq.ExpireItems(params)
	}
	return common.InvalidRequest("Unknown action: " + cmd)
}
Example #4
0
// Context changer.
func (s *SessionHandler) setCtxHandler(tokens []string) iface.IResponse {
	if len(tokens) > 1 {
		return common.InvalidRequest("SETCTX accept service name only")
	}

	if len(tokens) == 0 {
		return common.InvalidRequest("Service name must be provided")
	}

	svcName := tokens[0]
	svc, exists := s.svcs.GetService(svcName)
	if !exists {
		return common.ERR_NO_SVC
	}
	s.ctx = svc
	return common.OK_RESPONSE
}
Example #5
0
// List all active services.
func (s *SessionHandler) listServicesHandler(tokens []string) iface.IResponse {
	svcPrefix := ""
	svcType := ""
	if len(tokens) == 1 {
		svcPrefix = tokens[0]
	} else if len(tokens) == 2 {
		svcType = tokens[1]
	} else if len(tokens) > 2 {
		return common.InvalidRequest("LIST accept service name prefix and service type only")
	}

	return s.svcs.ListServices(svcPrefix, svcType)
}
Example #6
0
// Handler that creates a service.
func (s *SessionHandler) createServiceHandler(tokens []string) iface.IResponse {
	if len(tokens) < 2 {
		return common.InvalidRequest("At least service type and name should be provided")
	}
	svcName := tokens[0]
	svcType := tokens[1]

	_, exists := s.svcs.GetService(svcName)
	if exists {
		return common.ConflictRequest("Service exists already")
	}

	resp := s.svcs.CreateService(svcType, svcName, make([]string, 0))
	return resp
}
Example #7
0
func makeUnknownParamResponse(paramName string) *common.ErrorResponse {
	return common.InvalidRequest(fmt.Sprintf("Unknown parameter: %s", paramName))
}