Example #1
0
func (dfs *DistributedFilesystem) desynchronize(image *docker.Image) error {
	// inspect the image
	dImg, err := image.Inspect()
	if err != nil {
		glog.Errorf("Could not inspect image %s (%s): %s", image.ID, image.UUID, err)
		return err
	}

	// look up services for that tenant
	svcs, err := dfs.facade.GetServices(datastore.Get(), dao.ServiceRequest{TenantID: image.ID.User})
	if err != nil {
		glog.Errorf("Could not get services for tenant %s from %s (%s): %s", image.ID.User, image.ID, image.UUID, err)
		return err
	}

	for _, svc := range svcs {
		// figure out which services are using the provided image
		svcImageID, err := commons.ParseImageID(svc.ImageID)
		if err != nil {
			glog.Warningf("Could not parse image %s for %s (%s): %s", svc.ImageID, svc.Name, svc.ID)
			continue
		} else if !svcImageID.Equals(image.ID) {
			continue
		}

		// TODO: we need to switch to using dao.ControlPlane
		conn, err := zzk.GetLocalConnection(zzk.GeneratePoolPath(svc.PoolID))
		if err != nil {
			glog.Warningf("Could not acquire connection to the coordinator (%s): %s", svc.PoolID, err)
			continue
		}

		states, err := zkservice.GetServiceStates(conn, svc.ID)
		if err != nil {
			glog.Warningf("Could not get running services for %s (%s): %s", svc.Name, svc.ID)
			continue
		}

		for _, state := range states {
			// check if the instance has been running since before the commit
			if state.IsRunning() && state.Started.Before(dImg.Created) {
				state.InSync = false
				if err := zkservice.UpdateServiceState(conn, &state); err != nil {
					glog.Warningf("Could not update service state %s for %s (%s) as out of sync: %s", state.ID, svc.Name, svc.ID, err)
					continue
				}
			}
		}
	}
	return nil
}
Example #2
0
func loadImage(filename string, uuid string, tags []string) error {
	// look up the image by UUID
	images, err := docker.Images()
	if err != nil {
		glog.Errorf("Could not look up images: %s", err)
		return err
	}

	var image *docker.Image
	for _, i := range images {
		if i.UUID == uuid {
			image = i
			break
		}
	}

	// image not found so import
	if image == nil {
		glog.Warningf("Importing image from file, don't forget to sync (serviced docker sync)")
		if err := docker.ImportImage(tags[0], filename); err != nil {
			glog.Errorf("Could not import image from file %s: %s", filename, err)
			return err
		} else if image, err = docker.FindImage(tags[0], false); err != nil {
			glog.Errorf("Could not look up docker image %s: %s", tags[0], err)
			return err
		}
		glog.Infof("Tagging images %v at %s", tags, image.UUID)
		tags = tags[1:]
	}

	// tag the remaining images
	for _, tag := range tags {
		if _, err := image.Tag(tag); err != nil {
			glog.Errorf("Could not tag image %s as %s: %s", image.UUID, tag, err)
			return err
		}
	}

	return nil
}
Example #3
0
func defaultTagImage(image *docker.Image, newTag string) (*docker.Image, error) {
	return image.Tag(newTag)
}