Ejemplo n.º 1
0
func main() {
	flag.Parse()

	c := client.NewHTTPClient(*address)
	if err := c.WaitUntilReady(*waitDuration); err != nil {
		log.Fatal(err)
	}

	serviceMethod, params := flag.Arg(0), json.RawMessage(flag.Arg(1))
	if *legacyCall {
		var resp json.RawMessage
		if err := c.Call(serviceMethod, &params, &resp); err != nil {
			log.Fatal(err)
		}
		fmt.Println(string(resp))
	} else {
		rd := c.Stream(serviceMethod, &params)
		defer rd.Close()
		for {
			var resp json.RawMessage
			if err := rd.NextResult(&resp); err == io.EOF {
				break
			} else if err != nil {
				log.Fatal(err)
			}
			fmt.Println(string(resp))
		}
	}
}
Ejemplo n.º 2
0
// startShipshapeService ensures that there is a service started with the given image and
// attached analyzers that can analyze the directory at absRoot (an absolute path). If a
// service is not started up that can do this, it will shut down the existing one and start
// a new one.
// The methods returns the (ready) client, the relative path from the docker container's mapped
// volume to the absRoot that we are analyzing, and any errors from attempting to run the service.
// TODO(ciera): This *should* check the analyzers that are connected, but does not yet
// do so.
func startShipshapeService(image, absRoot string, analyzers []string, dind bool) (*client.Client, string, error) {
	glog.Infof("Starting shipshape...")
	container := "shipping_container"
	// subPath is the relatve path from the mapped volume on shipping container
	// to the directory we are analyzing (absRoot)
	isMapped, subPath := docker.MappedVolume(absRoot, container)
	// Stop and restart the container if:
	// 1: The container is not using the latest image OR
	// 2: The container is not mapped to the right directory OR
	// 3: The container is not linked to the right analyzer containers
	// Otherwise, use the existing container
	if !docker.ImageMatches(image, container) || !isMapped || !docker.ContainsLinks(container, analyzers) {
		glog.Infof("Restarting container with %s", image)
		stop(container, 0)
		result := docker.RunService(image, container, absRoot, localLogs, analyzers, dind)
		subPath = ""
		printStreams(result)
		if result.Err != nil {
			return nil, "", result.Err
		}
	}
	glog.Infof("Image %s running in service mode", image)
	c := client.NewHTTPClient("localhost:10007")
	return c, subPath, c.WaitUntilReady(10 * time.Second)
}
Ejemplo n.º 3
0
// getHTTPClient provides a (cached) HTTPClient for the address specified.
func getHTTPClient(addr string) *client.Client {
	httpClient, exists := clients[addr]
	if !exists {
		clients[addr] = client.NewHTTPClient(addr)
		httpClient = clients[addr]
	}
	return httpClient
}
// TODO(supertri): utility methods to create request protos shared with test_analyzer_client?
func main() {
	flag.Parse()

	var root = ""
	var sourceContext *spb.SourceContext
	var err error

	switch *repoKind {
	case cloudRepo:
		sourceContext, root, err = file.SetupCloudRepo(*projectName, *hash, *repoBase, *volumeName)
		if err != nil {
			log.Fatalf("Failed to setup Cloud repo: %v", err)
		}
	case local:
		if *repoBase == "/tmp" {
			log.Fatal("Must specify the repo_base for local runs")
		}
		root = *repoBase
	default:
		log.Fatalf("Invalid repo kind %q", *repoKind)
	}

	var trigger = []string(nil)

	if len(*categories) > 0 {
		trigger = strings.Split(*categories, ",")
	}

	c := client.NewHTTPClient(*servicePort)
	var paths []string
	if *filePaths != "" {
		paths = strings.Split(*filePaths, ",")
	}
	var stageEnum ctxpb.Stage
	switch *stage {
	case "POST_BUILD":
		stageEnum = ctxpb.Stage_POST_BUILD
	case "PRE_BUILD":
		stageEnum = ctxpb.Stage_PRE_BUILD
	default:
		log.Fatalf("Invalid stage %q", *stage)
	}

	req := &rpcpb.ShipshapeRequest{
		TriggeredCategory: trigger,
		ShipshapeContext: &ctxpb.ShipshapeContext{
			FilePath:      paths,
			SourceContext: sourceContext,
			RepoRoot:      proto.String(root),
		},
		Event: proto.String(*event),
		Stage: stageEnum.Enum(),
	}
	log.Println("About to call out to the shipshape service")

	rd := c.Stream("/ShipshapeService/Run", req)
	defer rd.Close()
	for {
		var msg rpcpb.ShipshapeResponse
		if err := rd.NextResult(&msg); err == io.EOF {
			break
		} else if err != nil {
			log.Fatalf("Error from call: %v", err)
		}
		log.Printf("result:\n\n%v\n", proto.MarshalTextString(&msg))
	}

	log.Printf("Done.")
}