manifest

package
v1.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddCmd = &cobra.Command{
	Use:   "add [manifest-id] [PATH]",
	Short: "Add to manifest for upload.",
	Long:  `Add to manifest for upload.`,
	Args:  cobra.MinimumNArgs(2),
	Run: func(cmd *cobra.Command, args []string) {

		i, err := strconv.ParseInt(args[0], 10, 32)
		if err != nil {
			panic(err)
		}
		manifestId := int32(i)

		localBasePath := args[1]

		targetBasePath, _ := cmd.Flags().GetString("target_path")
		recursive, _ := cmd.Flags().GetBool("recursive")

		req := api.AddToManifestRequest{
			ManifestId:     manifestId,
			BasePath:       localBasePath,
			TargetBasePath: targetBasePath,
			Recursive:      recursive,
		}

		port := viper.GetString("agent.port")

		conn, err := grpc.Dial(":"+port, grpc.WithTransportCredentials(insecure.NewCredentials()))
		if err != nil {
			fmt.Println("Error connecting to GRPC Server: ", err)
			return
		}
		defer conn.Close()

		client := api.NewAgentClient(conn)
		manifestResponse, err := client.AddToManifest(context.Background(), &req)
		if err != nil {
			shared.HandleAgentError(err, fmt.Sprintf("Error: Unable to complete Add To Manifest command: %v", err))
			return
		}

		fmt.Println(manifestResponse.Status)
	},
}
View Source
var CreateCmd = &cobra.Command{
	Use:   "create [flags] [PATH] [...PATH]",
	Short: "Creates manifest for upload.",
	Long:  `Creates manifest for upload.`,
	Run: func(cmd *cobra.Command, args []string) {

		targetBasePath, _ := cmd.Flags().GetString("target_path")

		req := api.CreateManifestRequest{
			BasePath:       args[0],
			TargetBasePath: targetBasePath,
			Recursive:      true,
		}

		port := viper.GetString("agent.port")
		conn, err := grpc.Dial(":"+port, grpc.WithTransportCredentials(insecure.NewCredentials()))
		if err != nil {
			fmt.Println("Error connecting to GRPC Server: ", err)
			return
		}
		defer conn.Close()

		client := api.NewAgentClient(conn)
		manifestResponse, err := client.CreateManifest(context.Background(), &req)
		if err != nil {
			shared.HandleAgentError(err, fmt.Sprintf("Error: Unable to complete Create Manifest command: %v", err))
			return
		}

		fmt.Println("Manifest ID:", manifestResponse.ManifestId, "Message:", manifestResponse.Message)
	},
}
View Source
var DeleteCmd = &cobra.Command{
	Use:   "delete <manifest_id>",
	Short: "Deletes existing manifest.",
	Long:  `Deletes existing manifest.`,
	Args:  cobra.MinimumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {

		i, err := strconv.ParseInt(args[0], 10, 32)
		if err != nil {
			panic(err)
		}
		manifestId := int32(i)

		req := api.DeleteManifestRequest{
			ManifestId: manifestId,
		}

		port := viper.GetString("agent.port")

		conn, err := grpc.Dial(":"+port, grpc.WithTransportCredentials(insecure.NewCredentials()))
		if err != nil {
			fmt.Println("Error connecting to GRPC Server: ", err)
			return
		}
		defer conn.Close()

		client := api.NewAgentClient(conn)
		manifestResponse, err := client.DeleteManifest(context.Background(), &req)
		if err != nil {
			shared.HandleAgentError(err, fmt.Sprintf("Error: Unable to complete Delete Manifest command: %v", err))
			return
		}

		fmt.Println(manifestResponse)
	},
}
View Source
var ListCmd = &cobra.Command{
	Use:   "list [flags] <manifestId> [offset] [limit]",
	Short: "lists files for a manifest.",
	Long:  `Creates manifest for upload.`,
	Args:  cobra.MinimumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {

		limit := int32(100)
		offset := int32(0)

		i, err := strconv.ParseInt(args[0], 10, 32)
		if err != nil {
			panic(err)
		}
		manifestId := int32(i)

		if len(args) > 2 {
			i, err = strconv.ParseInt(args[2], 10, 32)
			if err != nil {
				panic(err)
			}
			offset = int32(i)
		}
		if len(args) > 1 {
			i, err = strconv.ParseInt(args[1], 10, 32)
			if err != nil {
				panic(err)
			}
			limit = int32(i)
		}

		req := api.ListManifestFilesRequest{
			ManifestId: manifestId,
			Offset:     offset,
			Limit:      limit,
		}

		port := viper.GetString("agent.port")
		conn, err := grpc.Dial(":"+port, grpc.WithTransportCredentials(insecure.NewCredentials()))
		if err != nil {
			fmt.Println("Error connecting to GRPC Server: ", err)
			return
		}
		defer conn.Close()

		client := api.NewAgentClient(conn)
		listFilesResponse, err := client.ListManifestFiles(context.Background(), &req)
		if err != nil {
			shared.HandleAgentError(err,
				fmt.Sprintf("Error: Unable to complete List Manifest command: %v", err))
			return
		}

		showFull, _ := cmd.Flags().GetBool("full")
		PrettyPrint(listFilesResponse, args[0], showFull)
	},
}
View Source
var ManifestCmd = &cobra.Command{
	Use:   "manifest",
	Short: "Lists upload sessions.",
	Long: `Renders a list of upload manifests and their current status. 

This list includes only upload manifests that are initiated from the current machine.`,
	Run: func(cmd *cobra.Command, args []string) {

		req := api.ListManifestsRequest{}

		port := viper.GetString("agent.port")
		conn, err := grpc.Dial(":"+port, grpc.WithTransportCredentials(insecure.NewCredentials()))
		if err != nil {
			fmt.Println("Error connecting to GRPC Server: ", err)
			return
		}
		defer conn.Close()

		client := api.NewAgentClient(conn)
		manifestResponse, err := client.ListManifests(context.Background(), &req)
		if err != nil {
			st := status.Convert(err)
			fmt.Println(st.Message())
			return
		}

		t := table.NewWriter()
		t.SetOutputMirror(os.Stdout)
		t.AppendHeader(table.Row{"Upload Manifest", "User Name", "Organization Name", "Dataset ID", "Status", "nodeId"})
		for _, s := range manifestResponse.Manifests {
			const maxLength = 100
			dsName := trimName(s.DatasetName, maxLength)
			t.AppendRow([]interface{}{s.Id, s.UserName, s.OrganizationName, dsName, s.Status, s.NodeId})
		}

		t.Render()
	},
}
View Source
var RemoveCmd = &cobra.Command{
	Use:   "remove <MANIFEST-ID> <ID> [...ID]",
	Short: "Removes files from an existing manifest.",
	Long:  `Creates manifest for upload.`,
	Run: func(cmd *cobra.Command, args []string) {

		manifestId, _ := cmd.Flags().GetInt32("manifest_id")
		fmt.Println("manifest if ", manifestId)
		if manifestId == -1 {
			log.Fatalln("Need to specify manifest id with `manifest_id` flag.")
		}

		fmt.Println(args[0])

		req := api.RemoveFromManifestRequest{
			ManifestId: manifestId,
			RemovePath: args[0],
		}

		port := viper.GetString("agent.port")

		conn, err := grpc.Dial(":"+port, grpc.WithTransportCredentials(insecure.NewCredentials()))
		if err != nil {
			fmt.Println("Error connecting to GRPC Server: ", err)
			return
		}
		defer conn.Close()

		client := api.NewAgentClient(conn)
		manifestResponse, err := client.RemoveFromManifest(context.Background(), &req)
		if err != nil {
			shared.HandleAgentError(err, fmt.Sprintf("Error: Unable to complete Remove Manifest command: %v", err))
			return
		}

		fmt.Println(manifestResponse.Status)
	},
}
View Source
var ResetCmd = &cobra.Command{
	Use:   "reset <MANIFEST-ID> <ID> [...ID]",
	Short: "Resets status of all files in a manifest",
	Long:  `Resets status of all files in a manifest.`,
	Run: func(cmd *cobra.Command, args []string) {

		manifestId, _ := cmd.Flags().GetInt32("manifest_id")
		if manifestId == -1 {
			log.Fatalln("Need to specify manifest id with `manifest_id` flag.")
		}

		req := api.ResetManifestRequest{
			ManifestId: manifestId,
		}

		port := viper.GetString("agent.port")

		conn, err := grpc.Dial(":"+port, grpc.WithTransportCredentials(insecure.NewCredentials()))
		if err != nil {
			fmt.Println("Error connecting to GRPC Server: ", err)
			return
		}
		defer conn.Close()

		client := api.NewAgentClient(conn)
		manifestResponse, err := client.ResetManifest(context.Background(), &req)
		if err != nil {
			shared.HandleAgentError(err, fmt.Sprintf("Error: Unable to complete Reset Manifest command: %v", err))
			return
		}

		fmt.Println(manifestResponse.Status)
	},
}
View Source
var SyncCmd = &cobra.Command{
	Use:   "sync [flags] [MANIFEST ID] ",
	Short: "Syncs manifest with server.",
	Long:  `Synchronizes the manifest with the Pennsieve platform. `,
	Run: func(cmd *cobra.Command, args []string) {

		i, err := strconv.ParseInt(args[0], 10, 32)
		if err != nil {
			panic(err)
		}
		manifestId := int32(i)

		req := api.SyncManifestRequest{
			ManifestId: manifestId,
		}

		port := viper.GetString("agent.port")
		conn, err := grpc.Dial(":"+port, grpc.WithTransportCredentials(insecure.NewCredentials()))
		if err != nil {
			fmt.Println("Error connecting to GRPC Server: ", err)
			return
		}
		defer conn.Close()

		client := api.NewAgentClient(conn)
		_, err = client.SyncManifest(context.Background(), &req)
		if err != nil {
			shared.HandleAgentError(err, fmt.Sprintf("Error: Unable to complete Sync Manifest command: %v", err))
			return
		}

		s1 := rand.NewSource(time.Now().UnixNano())
		r1 := rand.New(s1)
		SubscribeClient, err := subscriber.NewSubscriberClient(int32(r1.Intn(100)))
		if err != nil {
			log.Fatal(err)
		}

		fmt.Printf("Synchronizing manifest.\n You can safely Ctr-C as synchronization will continue to run in the background.")
		fmt.Println("\n\nUse " +
			"\"pennsieve agent subscribe\" to track all events from the Pennsieve Agent.")

		fmt.Println("\n------------")
		SubscribeClient.Start([]api.SubscribeResponse_MessageType{api.SubscribeResponse_SYNC_STATUS}, subscriber.StopOnStatus{
			Enable: true,
			OnType: []api.SubscribeResponse_MessageType{api.SubscribeResponse_SYNC_STATUS},
		})

	},
}

Functions

func PrettyPrint

func PrettyPrint(files *api.ListManifestFilesResponse, manifestID string, showFull bool)

PrettyPrint renders a table with current userinfo to terminal

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL