Пример #1
0
// These are things we want to *always* control. Should be last
// called before a return...
func ServiceFinalizeLoad(srv *definitions.ServiceDefinition) {
	// If no name use image name
	if srv.Name == "" {
		logger.Debugf("Service definition has no name. ")
		if srv.Service.Name != "" {
			logger.Debugf("Defaulting to service name =>\t%s\n", srv.Service.Name)
			srv.Name = srv.Service.Name
		} else {
			if srv.Service.Image != "" {
				srv.Name = strings.Replace(srv.Service.Image, "/", "_", -1)
				srv.Service.Name = srv.Name
				logger.Debugf("Defaulting to image name =>\t%s\n", srv.Name)
			} else {
				panic("Service's Image should have been set before reaching ServiceFinalizeLoad")
			}
		}
	}

	container := util.FindServiceContainer(srv.Name, srv.Operations.ContainerNumber, true)

	if container != nil {
		logger.Debugf("Setting SrvCont Names =>\t%s:%s\n", container.FullName, container.ContainerID)
		srv.Operations.SrvContainerName = container.FullName
		srv.Operations.SrvContainerID = container.ContainerID
	} else {
		srv.Operations.SrvContainerName = util.ServiceContainersName(srv.Name, srv.Operations.ContainerNumber)
		srv.Operations.DataContainerName = util.ServiceToDataContainer(srv.Operations.SrvContainerName)
	}
	if srv.Service.AutoData {
		dataContainer := util.FindDataContainer(srv.Name, srv.Operations.ContainerNumber)
		if dataContainer != nil {
			logger.Debugf("Setting DataCont Names =>\t%s:%s\n", dataContainer.FullName, dataContainer.ContainerID)
			srv.Operations.DataContainerName = dataContainer.FullName
			srv.Operations.DataContainerID = dataContainer.ContainerID
		} else {
			srv.Operations.SrvContainerName = util.ServiceContainersName(srv.Name, srv.Operations.ContainerNumber)
			srv.Operations.DataContainerName = util.ServiceToDataContainer(srv.Operations.SrvContainerName)
		}
	}
}
Пример #2
0
// These are things we want to *always* control. Should be last
// called before a return...
func ServiceFinalizeLoad(srv *definitions.ServiceDefinition) {
	if srv.Name == "" && srv.Service.Name == "" && srv.Service.Image == "" { // If no name or image, panic
		panic("Service's Image should have been set before reaching ServiceFinalizeLoad")
	} else if srv.Name == "" && srv.Service.Name == "" && srv.Service.Image != "" { // If no name use image
		srv.Name = strings.Replace(srv.Service.Image, "/", "_", -1)
		srv.Service.Name = srv.Name
		log.WithField("image", srv.Name).Debug("Defaulting to image")
	} else if srv.Service.Name != "" && srv.Name == "" { // harmonize names
		srv.Name = srv.Service.Name
		log.WithField("service", srv.Service.Name).Debug("Defaulting to service")
	} else if srv.Service.Name == "" && srv.Name != "" {
		srv.Service.Name = srv.Name
		log.WithField("service", srv.Name).Debug("Defaulting to service")
	}

	container := util.FindServiceContainer(srv.Name, srv.Operations.ContainerNumber, true)

	if container != nil {
		log.WithField("=>", container.FullName).Debug("Setting service container name")
		srv.Operations.SrvContainerName = container.FullName
		srv.Operations.SrvContainerID = container.ContainerID
	} else {
		srv.Operations.SrvContainerName = util.ServiceContainersName(srv.Name, srv.Operations.ContainerNumber)
		srv.Operations.DataContainerName = util.ServiceToDataContainer(srv.Operations.SrvContainerName)
	}
	if srv.Service.AutoData {
		dataContainer := util.FindDataContainer(srv.Name, srv.Operations.ContainerNumber)
		if dataContainer != nil {
			log.WithField("=>", dataContainer.FullName).Debug("Setting data container name")
			srv.Operations.DataContainerName = dataContainer.FullName
			srv.Operations.DataContainerID = dataContainer.ContainerID
		} else {
			srv.Operations.SrvContainerName = util.ServiceContainersName(srv.Name, srv.Operations.ContainerNumber)
			srv.Operations.DataContainerName = util.ServiceToDataContainer(srv.Operations.SrvContainerName)
		}
	}
}