Ejemplo n.º 1
0
func ImportData(do *definitions.Do) error {
	if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {

		containerName := util.DataContainersName(do.Name, do.Operations.ContainerNumber)
		importPath := filepath.Join(DataContainersPath, do.Name)

		// temp until docker cp works both ways.
		logger.Debugf("Importing FROM =>\t\t%s\n", importPath)
		os.Chdir(importPath)
		// TODO [eb]: deal with hardcoded user
		// TODO [csk]: drop the whole damn cmd call
		//         use go's tar lib to make a tarball of the directory
		//         read the tar file into an io.Reader
		//         start a container with its Stdin open, connect to an io.Writer
		//         connect them up with io.Pipe
		//         this will free us from any quirks that the cli has
		if do.Path != "" {
			do.Path = do.Path
		} else {
			do.Path = "/home/eris/.eris"
		}

		logger.Debugf("Importing TO =>\t\t\t%s\n", do.Path)
		cmd := "tar chf - . | docker run -i --rm --volumes-from " + containerName + " --user eris eris/data tar xf - -C " + do.Path
		_, err := pipes.RunString(cmd)
		if err != nil {
			cmd := "tar chf - . | docker run -i --volumes-from " + containerName + " --user eris eris/data tar xf - -C " + do.Path
			_, e2 := pipes.RunString(cmd)
			if e2 != nil {
				return fmt.Errorf("Could not import the data container.\nTried with docker --rm =>\t%v\nTried without docker --rm =>\t%v", err, e2)
			}
		}
	} else {
		if err := perform.DockerCreateDataContainer(do.Name, do.Operations.ContainerNumber); err != nil {
			return fmt.Errorf("Error creating data container %v.", err)
		}
		return ImportData(do)
	}
	do.Result = "success"
	return nil
}
Ejemplo n.º 2
0
// Throw away chains are used for eris contracts
func ThrowAwayChain(do *definitions.Do) error {
	do.Name = do.Name + "_" + strings.Split(uuid.New(), "-")[0]
	do.Path = filepath.Join(ChainsPath, "default")
	logger.Debugf("Making a ThrowAwayChain =>\t%s:%s\n", do.Name, do.Path)

	if err := NewChain(do); err != nil {
		return err
	}

	logger.Debugf("ThrowAwayChain created =>\t%s\n", do.Name)
	do.Run = true  // turns on edb api
	StartChain(do) // XXX [csk]: may not need to do this now that New starts....
	logger.Debugf("ThrowAwayChain started =>\t%s\n", do.Name)
	return nil
}
Ejemplo n.º 3
0
// Throw away chains are used for eris contracts
func ThrowAwayChain(do *definitions.Do) error {
	do.Name = do.Name + "_" + strings.Split(uuid.New(), "-")[0]
	do.Path = filepath.Join(ChainsPath, "default")
	log.WithFields(log.Fields{
		"=>":   do.Name,
		"path": do.Path,
	}).Debug("Making a throaway chain")

	if err := NewChain(do); err != nil {
		return err
	}

	log.WithField("=>", do.Name).Debug("Throwaway chain created")
	do.Run = true  // turns on edb api
	StartChain(do) // XXX [csk]: may not need to do this now that New starts....
	log.WithField("=>", do.Name).Debug("Throwaway chain started")
	return nil
}
Ejemplo n.º 4
0
func RunPackage(do *definitions.Do) error {
	logger.Debugf("Welcome! Say the Marmots. Running DApp package.\n")
	pwd, err := os.Getwd()
	if err != nil {
		return fmt.Errorf("Could not get the present working directory. Are you on Mars?\nError: %v\n", err)
	}

	logger.Debugf("\twith Host Path =>\t%s:%s\n", do.Path, pwd)
	dapp, err := loaders.LoadContractPackage(do.Path, do.ChainName, do.Name, do.Type)
	if err != nil {
		do.Result = "could not load package"
		return err
	}

	if err := BootServicesAndChain(do, dapp); err != nil {
		do.Result = "could not boot chain or services"
		CleanUp(do, dapp)
		return err
	}

	do.Path = pwd
	if err := DefineDappActionService(do, dapp); err != nil {
		do.Result = "could not define dapp action service"
		CleanUp(do, dapp)
		return err
	}

	if err := PerformDappActionService(do, dapp); err != nil {
		do.Result = "could not perform dapp action service"
		CleanUp(do, dapp)
		return err
	}

	if err := CleanUp(do, dapp); err != nil {
		do.Result = "could not cleanup"
		return err
	}

	do.Result = "success"
	return nil
}
Ejemplo n.º 5
0
func RunPackage(do *definitions.Do) error {
	log.Debug("Welcome! Say the marmots. Running app package")
	var err error
	pwd, err = os.Getwd()
	if err != nil {
		return fmt.Errorf("Could not get the present working directory. Are you on Mars?\nError: %v\n", err)
	}

	log.WithFields(log.Fields{
		"host path": do.Path,
		"pwd":       pwd,
	}).Debug()
	app, err := loaders.LoadContractPackage(do.Path, do.ChainName, do.Name, do.Type)
	if err != nil {
		do.Result = "could not load package"
		return err
	}

	if err := BootServicesAndChain(do, app); err != nil {
		do.Result = "could not boot chain or services"
		CleanUp(do, app)
		return err
	}

	do.Path = pwd
	if err := DefineAppActionService(do, app); err != nil {
		do.Result = "could not define app action service"
		CleanUp(do, app)
		return err
	}

	if err := PerformAppActionService(do, app); err != nil {
		do.Result = "could not perform app action service"
		CleanUp(do, app)
		return err
	}

	do.Result = "success"
	return CleanUp(do, app)
}
Ejemplo n.º 6
0
// Throw away chains are used for eris contracts
func ThrowAwayChain(do *definitions.Do) error {
	do.Name = do.Name + "_" + strings.Split(uuid.New(), "-")[0]
	do.Path = filepath.Join(ChainsConfigPath, "default")
	logger.Debugf("Making a ThrowAwayChain =>\t%s:%s\n", do.Name, do.Path)

	if err := NewChain(do); err != nil {
		return err
	}

	logger.Debugf("ThrowAwayChain created =>\t%s\n", do.Name)

	// fakeId := strings.Split(uuid.New(), "-")[0]
	// srv, err := loaders.MockChainDefinition(do.Name, fakeId, true, 1)
	// if err != nil {
	// 	return err
	// }

	StartChain(do)

	logger.Debugf("ThrowAwayChain started =>\t%s\n", do.Name)
	return nil
}
Ejemplo n.º 7
0
func ExportData(do *definitions.Do) error {
	if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {
		logger.Infoln("Exporting data container", do.Name)

		exportPath := filepath.Join(DataContainersPath, do.Name) // TODO: do.Operations.ContainerNumber ?
		srv := PretendToBeAService(do.Name, do.Operations.ContainerNumber)

		service, exists := perform.ContainerExists(srv.Operations)

		if !exists {
			return fmt.Errorf("There is no data container for that service.")
		}
		logger.Infoln("Service ID: " + service.ID)

		cont, err := util.DockerClient.InspectContainer(service.ID)
		if err != nil {
			return err
		}

		reader, writer := io.Pipe()

		if do.Path != "" {
			do.Path = do.Path
		} else {
			do.Path = "/home/eris/.eris"
		}
		opts := docker.CopyFromContainerOptions{
			OutputStream: writer,
			Container:    service.ID,
			Resource:     do.Path,
		}

		go func() {
			IfExit(util.DockerClient.CopyFromContainer(opts))
			writer.Close()
		}()

		err = util.Untar(reader, do.Name, exportPath)
		if err != nil {
			return err
		}

		// docker actually exports to a `_data` folder for volumes
		//   this section of the function moves whatever docker dumps
		//   into exportPath/_data into export. ranging through the
		//   volumes is probably overkill as we could just assume
		//   that it *was* `_data` but in case docker changes later
		//   we'll just keep it for now.
		os.Chdir(exportPath)
		var unTarDestination string
		for k, v := range cont.Volumes {
			if k == "/home/eris/.eris" {
				unTarDestination = filepath.Base(v)
			}
		}
		if err := moveOutOfDirAndRmDir(filepath.Join(exportPath, unTarDestination), exportPath); err != nil {
			return err
		}

		// now if docker dumps to exportPath/.eris we should remove
		//   move everything from .eris to exportPath
		if err := moveOutOfDirAndRmDir(filepath.Join(exportPath, ".eris"), exportPath); err != nil {
			return err
		}

	} else {
		return fmt.Errorf("I cannot find that data container. Please check the data container name you sent me.")
	}

	do.Result = "success"
	return nil
}
Ejemplo n.º 8
0
func ExportData(do *definitions.Do) error {
	if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {
		dVer, err := util.DockerClientVersion()
		if err != nil {
			return err
		}

		logger.Infoln("Exporting data container", do.Name)

		// we want to export to a temp directory.
		exportPath, err := ioutil.TempDir(os.TempDir(), do.Name) // TODO: do.Operations.ContainerNumber ?
		defer os.Remove(exportPath)
		if err != nil {
			return err
		}

		srv := PretendToBeAService(do.Name, do.Operations.ContainerNumber)
		service, exists := perform.ContainerExists(srv.Operations)

		if !exists {
			return fmt.Errorf("There is no data container for that service.")
		}

		cont, err := util.DockerClient.InspectContainer(service.ID)
		if err != nil {
			return err
		}

		reader, writer := io.Pipe()
		defer reader.Close()

		if do.Path != "" {
			do.Path = do.Path
		} else {
			do.Path = "/home/eris/.eris"
		}
		opts := docker.CopyFromContainerOptions{
			OutputStream: writer,
			Container:    service.ID,
			Resource:     do.Path,
		}

		go func() {
			logger.Infof("Copying out of Cont. ID =>\t%s\n", service.ID)
			logger.Debugf("\tPath =>\t\t\t%s\n", do.Path)
			IfExit(util.DockerClient.CopyFromContainer(opts))
			writer.Close()
		}()

		logger.Debugf("Untarring Package from Cont =>\t%s\n", exportPath)
		if err = util.Untar(reader, do.Name, exportPath); err != nil {
			return err
		}

		// docker actually exports to a `_data` folder for volumes
		//   this section of the function moves whatever docker dumps
		//   into exportPath/_data into export. ranging through the
		//   volumes is probably overkill as we could just assume
		//   that it *was* `_data` but in case docker changes later
		//   we'll just keep it for now. this is specific to 1.7 and
		//   below. For 1.8 we do not need to do this.
		os.Chdir(exportPath)
		var unTarDestination string
		for k, v := range cont.Volumes {
			if k == do.Path {
				unTarDestination = filepath.Base(v)
			}
		}
		logger.Debugf("Untarring to =>\t\t\t%s:%s\n", exportPath, unTarDestination)

		if dVer <= 1.7 {
			if err := moveOutOfDirAndRmDir(filepath.Join(exportPath, unTarDestination), exportPath); err != nil {
				return err
			}
		}

		// now if docker dumps to exportPath/.eris we should remove
		//   move everything from .eris to exportPath
		if err := moveOutOfDirAndRmDir(filepath.Join(exportPath, ".eris"), exportPath); err != nil {
			return err
		}

		// finally remove everything in the data directory and move
		//   the temp contents there
		prevDir := filepath.Join(DataContainersPath, do.Name)
		if _, err := os.Stat(prevDir); os.IsNotExist(err) {
			if e2 := os.MkdirAll(prevDir, 0666); e2 != nil {
				return fmt.Errorf("Error:\tThe marmots could neither find, nor had access to make the directory: (%s)\n", prevDir)
			}
		}
		ClearDir(prevDir)
		if err := moveOutOfDirAndRmDir(exportPath, prevDir); err != nil {
			return err
		}

	} else {
		return fmt.Errorf("I cannot find that data container. Please check the data container name you sent me.")
	}

	do.Result = "success"
	return nil
}