Ejemplo n.º 1
0
func run(c *cli.Context) {
	log.Debugln("[ENVMAN] - Work path:", envman.CurrentEnvStoreFilePath)

	if len(c.Args()) > 0 {
		doCmdEnvs, err := envman.ReadEnvs(envman.CurrentEnvStoreFilePath)
		if err != nil {
			log.Fatal("[ENVMAN] - Failed to load EnvStore:", err)
		}

		doCommand := c.Args()[0]

		doArgs := []string{}
		if len(c.Args()) > 1 {
			doArgs = c.Args()[1:]
		}

		cmdToExecute := CommandModel{
			Command:      doCommand,
			Environments: doCmdEnvs,
			Argumentums:  doArgs,
		}

		log.Debugln("[ENVMAN] - Executing command:", cmdToExecute)

		if exit, err := runCommandModel(cmdToExecute); err != nil {
			log.Error("[ENVMAN] - Failed to execute command:", err)
			os.Exit(exit)
		}

		log.Debugln("[ENVMAN] - Command executed")
	} else {
		log.Fatal("[ENVMAN] - No command specified")
	}
}
Ejemplo n.º 2
0
func sendAndReceiveWithQueueInternal(t *testing.T, redis *Transport) {

	// sender
	go func() {
		redis.RunSource(countingSource)
	}()

	// wait 2 seconds for sending to finish
	select {
	case res := <-senderChan:
		log.Debugln(res)
	case <-time.After(time.Second * 2):
		t.Fatalf("Sending did not finish in time")
	}

	//	receiver
	go func() {
		redis.RunSink(countingSink)
	}()

	// wait 2 seconds for sending to finish (it will timeout if 100 messages have not been received
	select {
	case res := <-receiverChan:
		log.Debugln(res)
	case <-time.After(time.Second * 2):
		t.Fatalf("Sending and receiving did not finish in time")
	}

}
Ejemplo n.º 3
0
// Resize handles a CLI event to resize an interactive docker run or docker exec
// window.
func (clnt *client) Resize(containerID, processFriendlyName string, width, height int) error {
	// Get the libcontainerd container object
	clnt.lock(containerID)
	defer clnt.unlock(containerID)
	cont, err := clnt.getContainer(containerID)
	if err != nil {
		return err
	}

	h, w := uint16(height), uint16(width)

	if processFriendlyName == InitFriendlyName {
		logrus.Debugln("libcontainerd: resizing systemPID in", containerID, cont.process.systemPid)
		return cont.process.hcsProcess.ResizeConsole(w, h)
	}

	for _, p := range cont.processes {
		if p.friendlyName == processFriendlyName {
			logrus.Debugln("libcontainerd: resizing exec'd process", containerID, p.systemPid)
			return p.hcsProcess.ResizeConsole(w, h)
		}
	}

	return fmt.Errorf("Resize could not find containerID %s to resize", containerID)

}
Ejemplo n.º 4
0
/* Used by Remove file, this rebuilds the splice and assigns
   the new array of Files to self */
func (self *Meta) pullFromFiles(node *Node, file *FilePointer) {

	whole_stash := false
	if file == nil {
		whole_stash = true
	}
	var new_files []Node
	for _, itr := range self.Files {
		if itr.Compare(node) && whole_stash {
			log.Debugln("skipping whole stash: ", itr.Id)
			continue
		} else if itr.Compare(node) && !whole_stash {
			var new_pointers []FilePointer
			for _, fitr := range itr.Pointers {
				if fitr.Compare(file) {
					log.Debugln("skipping file from stash")
					continue
				}
				new_pointers = append(new_pointers, fitr)
			}
			itr.Pointers = new_pointers
		}
		new_files = append(new_files, itr)
	}
	self.Files = new_files
	log.Debug("\n\n***\nFiles:\n\n", self.Files, "\n\n***\n\n")
	self.SaveStash()
}
Ejemplo n.º 5
0
func handleChannel(s *Stream, ch ssh.Channel, reqs <-chan *ssh.Request, handle func(*Stream)) {

	// handle requests receive for this Channel
	go func(in <-chan *ssh.Request) {
		for req := range in {
			logrus.Debugln("AdminTool -> Request of type:", req.Type, "len:", len(req.Type))
			logrus.Debugln("AdminTool -> Request payload:", string(req.Payload), "len:", len(req.Payload))

			if req.WantReply {
				req.Reply(false, nil)
			}
		}
		logrus.Debugln("AdminTool -> End of request GO chan")
	}(reqs)

	// read data from channel
	go func() {
		for {
			buffer := make([]byte, 64)
			n, err := ch.Read(buffer)
			if err != nil {
				if err.Error() == "EOF" {
					handleData(s, []byte{}, true)
					// all data received: handle Stream message
					handle(s)
					break
				} else {
					logrus.Fatalln("failed to read channel : " + err.Error())
				}
			}
			handleData(s, buffer[:n], false)
		}
	}()
}
Ejemplo n.º 6
0
func executeQuery(db *bolt.DB, query string) error {
	selectStatement, err := boltq.NewParser(strings.NewReader(query)).ParseSelect()
	if err == nil {
		log.Debugf("parsed select: %v", selectStatement)
		return executeSelect(selectStatement, db)
	} else {
		log.Debugln(err.Error())
	}

	updateStatement, err := boltq.NewParser(strings.NewReader(query)).ParseUpdate()
	if err == nil {
		log.Debugf("parsed update: %v", updateStatement)
		return executeUpdate(updateStatement, db)
	} else {
		log.Debugln(err.Error())
	}

	deleteStatement, err := boltq.NewParser(strings.NewReader(query)).ParseDelete()
	if err == nil {
		log.Debugf("parsed delete: %v", deleteStatement)
		return executeDelete(deleteStatement, db)
	} else {
		log.Debugln(err.Error())
	}

	return fmt.Errorf("cannot parse: %s", query)
}
Ejemplo n.º 7
0
func executeSelect(stmt *boltq.SelectStatement, db *bolt.DB) error {
	return db.View(func(tx *bolt.Tx) error {
		var bucket *bolt.Bucket

		for _, name := range stmt.BucketPath {
			log.Debugln("navigating to bucket", name)
			bucket = tx.Bucket([]byte(name))

			if bucket == nil {
				return fmt.Errorf("cannot find bucket %s", name)
			}
		}

		if containsAsterisk(stmt.Fields) {
			log.Debugln("interating keys")
			cursor := bucket.Cursor()

			for k, v := cursor.First(); k != nil; k, v = cursor.Next() {
				emitKeypair(k, v)
			}
		} else {
			for _, k := range stmt.Fields {
				keyBytes := []byte(k)
				v := bucket.Get(keyBytes)
				emitKeypair(keyBytes, v)
			}
		}

		return nil
	})
}
Ejemplo n.º 8
0
// load calls fn inside a View with the contents of the file. Caller
// must make a copy of the data if needed.
func (f *File) load(c context.Context, fn func([]byte)) error {
	defer log.Debugln("load:", f.dir.path, f.name)
	err := f.dir.fs.backend.View(c, func(ctx Context) error {
		b, err := ctx.Dir(f.dir.path)
		if err != nil {
			return err
		}
		v, err := b.Get(f.name)
		if err != nil {
			return err
		}
		if v == nil {
			return fuse.ESTALE
		}
		switch v := v.(type) {
		case []byte:
			fn(v)
		case *File: // hard link
			if !f.same_path(v) {
				log.Debugln(f.dir.path, f.name, "->", v.dir.path, v.name)
				return v.load(c, fn)
			}
		default:
		}
		return nil
	})
	return err
}
Ejemplo n.º 9
0
func TestSendReceiveQueueSemantics2(t *testing.T) {

	initChannels()

	inputQueue0 := fmt.Sprintf("queue:input0-%d", time.Now().UnixNano())
	outputQueue0 := fmt.Sprintf("queue:output0-%d", time.Now().UnixNano())
	t1 := NewTransport(getKafkaBrokers(), getZookeeperHosts(), inputQueue0, outputQueue0)
	t1.Connect()
	defer t1.Disconnect()

	inputQueue1 := outputQueue0
	outputQueue1 := fmt.Sprintf("queue:output1-%d", time.Now().UnixNano())
	t2 := NewTransport(getKafkaBrokers(), getZookeeperHosts(), inputQueue1, outputQueue1)
	t2.Connect()
	defer t2.Disconnect()

	inputQueue2 := outputQueue1
	outputQueue2 := fmt.Sprintf("queue:output2-%d", time.Now().UnixNano())
	t3 := NewTransport(getKafkaBrokers(), getZookeeperHosts(), inputQueue2, outputQueue2)
	t3.Connect()
	defer t3.Disconnect()

	go func() {
		t1.RunSource(countingSource)
	}()

	// wait x seconds for sending to finish
	select {
	case res := <-senderChan:
		log.Debugln(res)
	case <-time.After(time.Second * 90):
		t.Fatalf("Sending did not finish in time")
	}

	go func() {
		t2.RunProcessor(bridgeFunc)
	}()

	// wait x seconds for bridge to finish
	select {
	case res := <-bridgeChan:
		log.Debugln(res)
	case <-time.After(time.Second * 90):
		t.Fatalf("Bridiging did not finish in time")
	}

	go func() {
		t3.RunSink(countingSink1)
	}()

	// wait x seconds for sending to finish (it will timeout if maxMessages messages have not been received)
	select {
	case res := <-receiverChan:
		log.Debugln(res)
	case <-time.After(time.Second * 90):
		t.Fatalf("Receiving did not finish in time")
	}

	closeChannels()
}
Ejemplo n.º 10
0
func logEnvs() error {
	environments, err := envman.ReadEnvs(envman.CurrentEnvStoreFilePath)
	if err != nil {
		return err
	}

	if len(environments) == 0 {
		log.Info("[ENVMAN] - Empty envstore")
	} else {
		for _, env := range environments {
			key, value, err := env.GetKeyValuePair()
			if err != nil {
				return err
			}

			opts, err := env.GetOptions()
			if err != nil {
				return err
			}

			envString := "- " + key + ": " + value
			log.Debugln(envString)
			if !*opts.IsExpand {
				expandString := "  " + "isExpand" + ": " + "false"
				log.Debugln(expandString)
			}
		}
	}

	return nil
}
Ejemplo n.º 11
0
// stdouterrAccept runs as a go function. It waits for the container system to
// accept our offer of a named pipe - in fact two of them - one for stdout
// and one for stderr (we are called twice). Once the named pipe is accepted,
// if we are running "attached" to the container (eg docker run -i), then we
// spin up a further thread to copy anything from the containers output channels
// to the client.
func stdouterrAccept(outerrListen *npipe.PipeListener, pipeName string, copyto io.Writer) {

	// Wait for the pipe to be connected to by the shim
	logrus.Debugln("out/err: Waiting on ", pipeName)
	outerrConn, err := outerrListen.Accept()
	if err != nil {
		logrus.Errorf("Failed to accept on pipe %s %s", pipeName, err)
		return
	}
	logrus.Debugln("Connected to ", outerrConn.RemoteAddr())

	// Anything that comes from the container named pipe stdout/err should be copied
	// across to the stdout/err of the client
	if copyto != nil {
		go func() {
			defer outerrConn.Close()
			logrus.Debugln("Calling io.Copy on ", pipeName)
			bytes, err := io.Copy(copyto, outerrConn)
			logrus.Debugf("Copied %d bytes from pipe=%s", bytes, outerrConn.RemoteAddr())
			if err != nil {
				// Not fatal, just debug log it
				logrus.Debugf("Error hit during copy %s", err)
			}
		}()
	} else {
		defer outerrConn.Close()
	}
}
Ejemplo n.º 12
0
func (sr *Runner) getChecks(maxChecks int, timeout int) []stalker.Check {
	log.Debugln("Getting checks off queue")
	checks := make([]stalker.Check, 0)
	expireTime := time.Now().Add(3 * time.Second).Unix()
	for len(checks) <= maxChecks {
		//we've exceeded our try time
		if time.Now().Unix() > expireTime {
			break
		}
		rconn := sr.rpool.Get()
		defer rconn.Close()
		res, err := redis.Values(rconn.Do("BLPOP", sr.conf.workerQueue, timeout))
		if err != nil {
			if err != redis.ErrNil {
				log.Errorln("Error grabbing check from queue:", err.Error())
				break
			} else {
				log.Debugln("redis result:", err)
				continue
			}
		}
		var rb []byte
		res, err = redis.Scan(res, nil, &rb)
		var check stalker.Check
		if err := json.Unmarshal(rb, &check); err != nil {
			log.Errorln("Error decoding check from queue to json:", err.Error())
			break
		}
		checks = append(checks, check)
	}
	return checks
}
Ejemplo n.º 13
0
func add(c *cli.Context) {
	log.Debugln("[ENVMAN] - Work path:", envman.CurrentEnvStoreFilePath)

	key := c.String(KeyKey)
	expand := !c.Bool(NoExpandKey)
	replace := !c.Bool(AppendKey)

	var value string
	if stdinValue != "" {
		value = stdinValue
	} else if c.IsSet(ValueKey) {
		value = c.String(ValueKey)
	} else if c.String(ValueFileKey) != "" {
		if v, err := loadValueFromFile(c.String(ValueFileKey)); err != nil {
			log.Fatal("[ENVMAN] - Failed to read file value: ", err)
		} else {
			value = v
		}
	}

	if err := addEnv(key, value, expand, replace); err != nil {
		log.Fatal("[ENVMAN] - Failed to add env:", err)
	}

	log.Debugln("[ENVMAN] - Env added")

	if err := logEnvs(); err != nil {
		log.Fatal("[ENVMAN] - Failed to print:", err)
	}
}
Ejemplo n.º 14
0
func persist(db *bolt.DB, args []string) error {
	tx, err := db.Begin(true)
	if err != nil {
		return err
	}
	log.Debugln("start transaction.")
	for _, v := range args {
		log.Debugln(v)
		bucket := tx.Bucket([]byte(BUCKET_NAME))
		if bucket == nil {
			bucket, err = tx.CreateBucket([]byte(BUCKET_NAME))
			if err != nil {
				return err
			}
			count := btoi(bucket.Get([]byte(v)))
			count += 1
			err = bucket.Put([]byte(v), itob(count))
			if err != nil {
				tx.Rollback()
				return err
			}
		}
	}

	tx.Commit()
	return nil
}
Ejemplo n.º 15
0
func main() {
	log.SetLevel(log.DebugLevel)
	log.Infoln("*******************************************")
	log.Infoln("Port Scanner")
	log.Infoln("*******************************************")

	t := time.Now()
	defer func() {
		if e := recover(); e != nil {
			log.Debugln(e)
		}
	}()

	log.Debugln(loadConfig("config.properties"))

	log.Debugln("Parsed input data ", len(portScannerTuple.portScannerResult))
	CheckPort(&portScannerTuple)

	for key, value := range portScannerTuple.portScannerResult {
		if value {
			log.Debugln("Port Scanner Result", key, " port is open :", value)
		}
	}

	log.Debugln("Total time taken %s to scan %d ports", time.Since(t), len(portScannerTuple.portScannerResult))
}
Ejemplo n.º 16
0
func main() {

	var (
		configDir   string
		hideConsole bool
		showConsole bool
		debugLog    bool
	)

	flag.StringVar(&configDir, "configdir", "", "Configuration directory")
	flag.BoolVar(&hideConsole, "hidecon", false, "Hide console")
	flag.BoolVar(&showConsole, "showcon", false, "Show console")
	flag.BoolVar(&debugLog, "debuglog", false, "Show console")
	flag.Parse()
	//log.Debugln("Command line: " + flag.CommandLine)

	log.SetOutput(os.Stderr)
	log.SetLevel(log.DebugLevel)

	log.Debugln("os.Args: ", os.Args)
	log.Debugln("ConfigDir: ", configDir)
	if configDir != "" {
		Locations[LocationConfigFile] = configDir
	}
	InitLocations()
	throughBox.LoadConfig(Locations[LocationConfigFile], true)

	//	for _, item := range PortMapList {
	//		fmt.Printf("%#v %#v %#v \n", item.Port, *(item.SourceIP), item.DestinationAdress)
	//	}

	log.Debugln("Start")
	throughBox.Start()
	throughBox.Wait()
}
Ejemplo n.º 17
0
// newSSH2Client constructs a connected ClientTransport to addr based on HTTP2
// and starts to receive messages on it. Non-nil error returns if construction
// fails.
func newSSH2Client(addr string, opts *ConnectOptions) (_ ClientTransport, err error) {

	logrus.SetLevel(logrus.DebugLevel)

	logrus.Debugln("newSSH2Client")
	logrus.Debugln("newSSH2Client -- addr:", addr)
	logrus.Debugln("newSSH2Client -- opts:", opts)

	// generate hostKey, needed to ssh connect
	appPath, err := osext.Executable()
	if err != nil {
		return nil, err
	}
	keyPath := filepath.Join(filepath.Dir(appPath), "key.pem")
	hostKey, err := sshutil.KeyLoader{Path: keyPath, Flags: sshutil.Create + sshutil.Save + sshutil.RSA2048}.Load()
	if err != nil {
		return nil, err
	}

	config := &ssh.ClientConfig{
		User: "******",
		Auth: []ssh.AuthMethod{
			ssh.Password("test"),
			ssh.PublicKeys(hostKey),
		},
	}

	// client is an ssh.Client with is of type ssh.Conn
	client, err := ssh.Dial("tcp", addr, config)

	if err != nil {
		return nil, ConnectionErrorf("transport: %v", err)
	}

	// Ad: original code sends http2.ClientPreface here (conn.Write)
	// I don't think it's needed in our case. We have SSH auth, subsystems...

	// Ad: then creates a new "framer"
	// We will implement this differently. From what I understood, each frame comes with a header
	// And it allows get the corresponding stream...etc
	// In our case, each request will have its dedicated ssh Channel (Stream), so we don't have
	// to do any logic to find the context.

	t := &ssh2Client{
		conn:               client,
		writableChan:       make(chan int, 1),
		shutdownChan:       make(chan struct{}),
		errorChan:          make(chan struct{}),
		controlBuf:         newRecvBuffer(),
		sendQuotaPool:      newQuotaPool(defaultWindowSize),
		state:              reachable,
		streamSendQuota:    defaultWindowSize,
		channelsByStreamId: make(map[uint32]*ssh.Channel),
	}

	t.writableChan <- 0
	return t, nil
}
Ejemplo n.º 18
0
/* De-duplicate staging / stash note this should be private to
   Meta */
func (self *Meta) append(stgNode Node, stgFile *os.File) {

	pointer := stgNode.Pointers[0] //there can only be one here!
	log.Debugln("A dump of our file so far:\n***\n %v\n\n***", stgNode)
	defer self.RebuildLookup() //we can do this nomatter what the outcome
	defer self.SaveStash()
	for itr := range self.Files { //loop over everything in the stash if we have to
		node := &self.Files[itr]
		log.Debugln("Comparing to:", node.Id)
		if node.ChkSum == stgNode.ChkSum { //we have a flat out duplicate
			log.Info("Found a duplicate of ", node.Id)
			pointer.Version = len(node.Pointers)
			node.Pointers = append(node.Pointers, pointer)
			node.PickupCount += 1
			stgFile.Close()
			os.Remove(config.Staging_loc + "/" + stgNode.Id)
			return
		}
		stashfl, err := os.Open(config.Stash_loc + "/" + node.Id)
		if err != nil {
			log.Errorln("Failed to open stash file: ", node.Id)
			break //TODO; is it possible that this could introduce a zombi?
		}
		leftCheck, _ := self.calcMd5sum(stashfl, stgNode.Size)
		stashfl.Close()
		log.Debugln("LeftCheck for stgNode.size; ", stgNode.Size, " is: ", leftCheck)
		if leftCheck == stgNode.ChkSum { //incoming file is a partial of this file
			log.Info("Incoming file is a partial of: ", node.Id)
			pointer.Version = len(node.Pointers)
			node.Pointers = append(node.Pointers, pointer)
			node.PartialCount += 1
			stgFile.Close() //we only add the pointer and remove the staged file
			os.Remove(config.Staging_loc + "/" + stgNode.Id)
			return
		}
		stgFile.Seek(0, 0)
		rightCheck, _ := self.calcMd5sum(stgFile, node.Size)
		log.Debugln("RightCheck for stgNode.size; ", stgNode.Size, " is: ", rightCheck)
		if rightCheck == node.ChkSum { //stashed file is a partial of the incoming file
			log.Info("Stashed file ", node.Id, " is a partial of incoming file")
			pointer.Version = len(node.Pointers)
			node.Pointers = append(node.Pointers, pointer)
			node.PickupCount += 1
			node.PartialCount += 1
			stgFile.Close() //we keep the incoming file and ditch the staged file, keep the old id
			os.Rename(config.Staging_loc+"/"+stgNode.Id, config.Stash_loc+"/"+node.Id)
			node.Size = stgNode.Size
			node.ChkSum = stgNode.ChkSum
			return
		}
	} //stage file is unique to the stash, add and move
	log.Info("New file is unique, adding to stash as", stgNode.Id)
	stgFile.Close()
	self.Files = append(self.Files, stgNode) // this happens if we are not a duplicate or partial
	self.Count = len(self.Files)
	os.Rename(config.Staging_loc+"/"+stgNode.Id, config.Stash_loc+"/"+stgNode.Id)
	return
}
Ejemplo n.º 19
0
func countingSink(input <-chan *api.Message) {
	log.Debugln("countingSink started")

	for i := 0; i < maxMessages; i++ {
		msg := <-input
		log.Debugln("Received message: ", msg)
	}
	receiverChan <- "countingSink"
}
Ejemplo n.º 20
0
func goBuildInIsolation(packageName, srcPath, outputBinPath string) error {
	log.Debugf("=> Installing package (%s) to path (%s) ...", packageName, srcPath)
	workspaceRootPath, err := pathutil.NormalizedOSTempDirPath("bitrise-go-toolkit")
	if err != nil {
		return fmt.Errorf("Failed to create root directory of isolated workspace, error: %s", err)
	}
	log.Debugln("=> Using sandboxed workspace:", workspaceRootPath)

	// origGOPATH := os.Getenv("GOPATH")
	// if origGOPATH == "" {
	// 	return fmt.Errorf("You don't have a GOPATH environment - please set it; GOPATH/bin will be symlinked")
	// }

	// log.Debugln("=> Symlink GOPATH/bin into sandbox ...")
	// if err := gows.CreateGopathBinSymlink(origGOPATH, workspaceRootPath); err != nil {
	// 	return fmt.Errorf("Failed to create GOPATH/bin symlink, error: %s", err)
	// }
	// log.Debugln("   [DONE]")

	fullPackageWorkspacePath := filepath.Join(workspaceRootPath, "src", packageName)
	log.Debugf("=> Creating Symlink: (%s) -> (%s)", srcPath, fullPackageWorkspacePath)
	if err := gows.CreateOrUpdateSymlink(srcPath, fullPackageWorkspacePath); err != nil {
		return fmt.Errorf("Failed to create Project->Workspace symlink, error: %s", err)
	}
	log.Debugf(" [DONE] Symlink is in place")

	log.Debugln("=> Building package " + packageName + " ...")
	{
		isInstallRequired, _, goConfig, err := selectGoConfiguration()
		if err != nil {
			return fmt.Errorf("Failed to select an appropriate Go installation for compiling the step, error: %s", err)
		}
		if isInstallRequired {
			return fmt.Errorf("Failed to select an appropriate Go installation for compiling the step, error: %s",
				"Found Go version is older than required. Please run 'bitrise setup' to check and install the required version")
		}

		cmd := gows.CreateCommand(workspaceRootPath, workspaceRootPath,
			goConfig.GoBinaryPath, "build", "-o", outputBinPath, packageName)
		cmd.Env = append(cmd.Env, "GOROOT="+goConfig.GOROOT)
		if err := cmd.Run(); err != nil {
			return fmt.Errorf("Failed to install package, error: %s", err)
		}
	}
	log.Debugln("   [DONE] Package successfully installed")

	log.Debugln("=> Delete isolated workspace ...")
	{
		if err := os.RemoveAll(workspaceRootPath); err != nil {
			return fmt.Errorf("Failed to delete temporary isolated workspace, error: %s", err)
		}
	}
	log.Debugln("   [DONE]")

	return nil
}
Ejemplo n.º 21
0
func (sr *Runner) stateHasChanged(check stalker.Check, previousStatus bool) bool {
	if check.Status != previousStatus {
		log.Debugln("state changed", check.Hostname, check.Check)
		sr.logStateChange(check)
		//statsd.counter('state_change')
		return true
	}
	log.Debugln("state unchanged:", check.Hostname, check.Check, previousStatus)
	return false
}
// Wraps the HTTP request with a semaphore to rate limit requests.
func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {

	// Get the sem for this request and try to aquire it.
	var sem chan struct{}
	if t.MaxConcurrencyPerHost > 0 {
		sem = t.getSem(req)
		sem <- nothing
	}

	// Make the request.
	resp, err := t.Transport.RoundTrip(req)
	if err != nil {

		// Check if we need to release the sem.
		if t.MaxConcurrencyPerHost > 0 {
			<-sem
		}

		// Return the error.
		return nil, err
	}

	// if this is a static request (i.e. req.URL matches static host and path)
	// then gsub 'static-root' out of Location. (from d.Service(req.Host, req.URL.Path))
	staticRoot := req.Header.Get("x-static-root")
	s3Location := resp.Header.Get("Location")
	s3Refresh := resp.Header.Get("Refresh")
	if staticRoot != "" {
		if s3Location != "" {
			resp.Header.Set("Location", strings.Replace(s3Location, staticRoot, "/", 1))
			log.Debugln("Location translated:", resp.Header.Get("Location"))
		} else if s3Refresh != "" {
			resp.Header.Set("Refresh", strings.Replace(s3Refresh, staticRoot, "/", 1))
			log.Debugln("Refresh translated:", resp.Header.Get("Refresh"))
		}
	}

	// Set a few debug headers.
	resp.Header.Set("x-kubernetes-url", req.URL.String())

	// Set up a sem release linked to the response being read.
	if t.MaxConcurrencyPerHost > 0 {
		resp.Body = &readCloserSem{resp.Body, sem}
	}

	// Check if we should compress the response.
	if t.CompressionLevel > 0 && compressionEnabledRequest(req) && compressableResponse(resp) {
		if err := compressResponse(resp, t.CompressionLevel); err != nil {
			return nil, err
		}
	}

	return resp, nil
}
Ejemplo n.º 23
0
func pubsubSink2(input <-chan *api.Message) {
	log.Debugln("pubsubSink2 started")
	for {
		msg := <-input
		log.Debugln("[pubsubSink2] Received first pubsub message: %s", msg.String())
		pubsubReceivingChan <- true
		pubsubStopSendingChan <- true
		break
	}

	countingSink2(input)
}
Ejemplo n.º 24
0
func (s *BotSuite) TestRun(c *C) {
	logrus.Debugln("1")
	b, _, err := BasicMockBot()
	defer b.Stop()
	logrus.Debugln("2")
	c.Check(err, IsNil)
	logrus.Debugln("3")
	c.Check(b, NotNil)
	go b.RunAllRooms()
	logrus.Debugln("4")
	time.Sleep(time.Second)
	logrus.Debugln("Stopping...")
}
Ejemplo n.º 25
0
// printBIRDPeers queries BIRD and displays the local peers in table format.
func printBIRDPeers(ipv string) {
	log.Debugf("Print BIRD peers for IPv%s", ipv)
	birdSuffix := ""
	if ipv == "6" {
		birdSuffix = "6"
	}

	fmt.Printf("\nIPv%s BGP status\n", ipv)

	// Try connecting to the bird socket in `/var/run/calico/` first to get the data
	c, err := net.Dial("unix", fmt.Sprintf("/var/run/calico/bird%s.ctl", birdSuffix))
	if err != nil {
		// If that fails, try connecting to bird socket in `/var/run/bird` (which is the
		// default socket location for bird install) for non-containerized installs
		log.Debugln("Failed to connect to BIRD socket in /var/run/calic, trying /var/run/bird")
		c, err = net.Dial("unix", fmt.Sprintf("/var/run/bird/bird%s.ctl", birdSuffix))
		if err != nil {
			fmt.Printf("Error querying BIRD: unable to connect to BIRDv%s socket: %v", ipv, err)
			return
		}
	}
	defer c.Close()

	// To query the current state of the BGP peers, we connect to the BIRD
	// socket and send a "show protocols" message.  BIRD responds with
	// peer data in a table format.
	//
	// Send the request.
	_, err = c.Write([]byte("show protocols\n"))
	if err != nil {
		fmt.Printf("Error executing command: unable to write to BIRD socket: %s\n", err)
		os.Exit(1)
	}

	// Scan the output and collect parsed BGP peers
	log.Debugln("Reading output from BIRD")
	peers, err := scanBIRDPeers(ipv, c)
	if err != nil {
		fmt.Printf("Error executing command: %v", err)
		os.Exit(1)
	}

	// If no peers were returned then just print a message.
	if len(peers) == 0 {
		fmt.Printf("No IPv%s peers found.\n", ipv)
		return
	}

	// Finally, print the peers.
	printPeers(peers)
}
Ejemplo n.º 26
0
/* Underlying meta management is done on the Meta object. Open stash
   implements the inital load of the data responsible for the stash.
   timed saves are made to the data store when run in daemon mode. */
func (self *Meta) OpenStash() {

	log.Info("Opening stash")
	//check for ~/.dropstash
	if _, err := os.Stat(config.Staging_loc); os.IsNotExist(err) {
		log.Warnf("No existing stash: %s, creating", config.Stash_loc)
		log.Warnf("No existing staging location: %s, creating", config.Staging_loc)
		os.MkdirAll(config.Staging_loc, 0700)
	}

	self.LoadStashFile()
	log.Println("Loaded available meta data")
	defer close(self.stash) //defer some cleanup
	curr_op := Operation{}  //get the next operation... better be start

	for curr_op.Code != Stop {
		log.Debugln("Processing opcodes and stash save")
		select { //get the next operation, and occasionally save the stash

		case <-time.After(config.Stash_save_seconds * time.Second):
			self.SaveStash()
		case curr_op = <-self.stash:
			log.Debugln("Processing next Operation:", curr_op.Code)
			if curr_op.Code == ProcessFile {
				fl, err := os.Open(config.Staging_loc + "/" + curr_op.Id)
				if err != nil {
					log.Errorln("Failed to open staging file:", curr_op.Id)
					continue
				}
				var file Node
				file.Id = curr_op.Id
				file.Overwrite = curr_op.Overwrite
				if fd, err := fl.Stat(); err != nil {
					log.Errorln("Failed to get stats on staged file:", file.Id)
					continue
				} else {
					file.Size = fd.Size()
				}
				file.ChkSum, err = self.calcMd5sum(fl, file.Size)
				file.PickupCount = 1
				file.PartialCount = 0
				pointer := FilePointer{curr_op.Name, curr_op.Location, file.Size, time.Now(), 0}
				file.Pointers = append(file.Pointers, pointer)
				//Now that we have a 'current file', we can append it to the stash
				self.append(file, fl) //Note that fl is closed in append
			}
		}
	}
	self.SaveStash() //make sure we clean up
	meta.stash <- curr_op
}
Ejemplo n.º 27
0
// ReadOldWorkflowModel ...
func ReadOldWorkflowModel(pth string) (oldModels.WorkflowModel, error) {
	bytes, err := fileutil.ReadBytesFromFile(pth)
	if err != nil {
		return oldModels.WorkflowModel{}, err
	}

	if strings.HasSuffix(pth, ".json") {
		log.Debugln("=> Using JSON parser for: ", pth)
		return WorkflowModelFromJSONBytes(bytes)
	}

	log.Debugln("=> Using YAML parser for: ", pth)
	return WorkflowModelFromYAMLBytes(bytes)
}
Ejemplo n.º 28
0
func GetStream(c *gin.Context) {

	repo := session.Repo(c)
	buildn, _ := strconv.Atoi(c.Param("build"))
	jobn, _ := strconv.Atoi(c.Param("number"))

	c.Writer.Header().Set("Content-Type", "text/event-stream")

	build, err := store.GetBuildNumber(c, repo, buildn)
	if err != nil {
		log.Debugln("stream cannot get build number.", err)
		c.AbortWithError(404, err)
		return
	}
	job, err := store.GetJobNumber(c, build, jobn)
	if err != nil {
		log.Debugln("stream cannot get job number.", err)
		c.AbortWithError(404, err)
		return
	}

	rc, err := stream.Reader(c, stream.ToKey(job.ID))
	if err != nil {
		c.AbortWithError(404, err)
		return
	}

	go func() {
		<-c.Writer.CloseNotify()
		rc.Close()
	}()

	var line int
	var scanner = bufio.NewScanner(rc)
	for scanner.Scan() {
		line++
		var err = sse.Encode(c.Writer, sse.Event{
			Id:    strconv.Itoa(line),
			Event: "message",
			Data:  scanner.Text(),
		})
		if err != nil {
			break
		}
		c.Writer.Flush()
	}

	log.Debugf("Closed stream %s#%d", repo.FullName, build.Number)
}
Ejemplo n.º 29
0
func latestVersionsForUser(s *Server, user *models.User, ids []string, isProduction bool) ([]versionResult, error) {
	var results []versionResult
	rrepo := s.DB.GetGameReleaseRepo()
	trepo := s.DB.GetTarballRepo()
	abUser, err := s.ab.UpdateUserTestGroups(user.ID, ids)
	if err != nil {
		return nil, err
	}
	for _, v := range ids {
		var gr *apipb.GameRelease
		var err error
		vr := versionResult{}
		tg := models.NoTestGroup
		for _, t := range abUser.Tests {
			if t.AppID == v {
				tg = t.TestGroup
				break
			}
		}
		if isProduction {
			gr, err = rrepo.GetLatestWithState(v, tg, apipb.ReleaseState_PRODUCTION)
			if err != nil {
				log.Debugln("common.go: error while getting latest version with state.", err)
				return nil, err
			}
		} else {
			gr, err = rrepo.GetLatest(v, tg)
			if err != nil {
				log.Debugln("common.go: error while getting latest version with Id.", err)
				return nil, err
			}
		}

		vr.GameID = gr.GameId
		vr.Version = gr.Version

		if isProduction {
			tarURL, errt := trepo.Get(gr.GameId, gr.Version)
			if errt != nil {
				log.Debugln("common.go: Error while getting Tarball URL.", errt)
				return nil, errt
			}
			vr.Url = tarURL.Url
		}

		results = append(results, vr)
	}
	return results, nil
}
Ejemplo n.º 30
0
func handleSignals() {
	// Graceful shut-down on SIGINT/SIGTERM
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	signal.Notify(c, syscall.SIGTERM)

	go func() {
		<-c
		logrus.Debugln("SIGTERM received.")
		logrus.Debugln("wait for running builds to finish.")
		running.Wait()
		logrus.Debugln("done.")
		os.Exit(0)
	}()
}