Commit b17a82ae authored by Kevin Di Lallo's avatar Kevin Di Lallo
Browse files

added meepctl status cli command + minor fixes to frontend replay pane

parent 4bd8a526
Loading
Loading
Loading
Loading
+78 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2020  InterDigital Communications, Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cmd

import (
	"context"
	"encoding/json"
	"fmt"

	"github.com/ghodss/yaml"
	"github.com/spf13/cobra"
)

// replayStatusCmd represents the replay status command
var replayStatusCmd = &cobra.Command{
	Use:     "status",
	Short:   "Retrieve replay status",
	Long:    "Retrieve replay execution status from backend.",
	Example: "meepctl replay status",
	Run: func(cmd *cobra.Command, args []string) {
		v, _ := cmd.Flags().GetBool("verbose")
		if v {
			fmt.Println("Replay status called")
			fmt.Println("[flag] verbose:", v)
		}
		replayStatus(cmd)
	},
}

func init() {
	replayCmd.AddCommand(replayStatusCmd)
}

func replayStatus(cobraCmd *cobra.Command) {
	verbose, _ := cobraCmd.Flags().GetBool("verbose")

	client, err := createClient(getBasePath())
	if err != nil {
		printError("Error creating client: ", err, verbose)
		return
	}

	status, _, err := client.EventReplayApi.GetReplayStatus(context.TODO())
	if err != nil {
		if err.Error() == "404 Not Found" {
			fmt.Println("Replay file not running...")
		} else {
			printError("Error: ", err, verbose)
		}
	} else {
		json, err := json.Marshal(status)
		if err != nil {
			printError("Error: ", err, verbose)
		}

		jsonToYaml, err := yaml.JSONToYAML(json)
		if err != nil {
			printError("Error converting JSON to YAML: ", err, verbose)
			return
		}

		fmt.Println(string(jsonToYaml))
	}
}
+24 −16
Original line number Diff line number Diff line
@@ -44,32 +44,34 @@ class EventReplayPane extends Component {
    };
  }

  triggerReplay(play) {
    if (play) {
      if (this.props.replayLoop) {
        this.props.api.loopReplay(this.props.replayFileSelected, (error) => {
  playReplay(name, loop) {
    if (name !== 'None') {
      if (loop) {
        this.props.api.loopReplay(name, (error) => {
          if (error) {
            // TODO consider showing an alert
            // console.log(error);
          }
        });
      } else {
        this.props.api.playReplayFile(this.props.replayFileSelected, (error) => {
        this.props.api.playReplayFile(name, (error) => {
          if (error) {
            // TODO consider showing an alert
            // console.log(error);
          }
        });
      }
    } else { //stop
      this.props.api.stopReplayFile(this.props.replayFileSelected, (error) => {
    }
  }

  stopReplay(name) {
    this.props.api.stopReplayFile(name, (error) => {
      if (error) {
        // TODO consider showing an alert
        // console.log(error);
      }
    });
  }
  }

  /**
   * Callback function to receive the result of the getReplayFile operation.
@@ -95,6 +97,12 @@ class EventReplayPane extends Component {
    return this.props.replayStatus ? true : false;
  }

  canPlay() {
    return !this.replayRunning() &&
      this.props.replayFileSelected &&
      this.props.replayFileSelected !== 'None';
  }

  render() {
    if (this.props.page !== PAGE_EXECUTE || this.props.hide) {
      return null;
@@ -144,16 +152,16 @@ class EventReplayPane extends Component {
              <Button
                outlined
                style={styles.button}
                onClick={() => this.triggerReplay(true)}
                disabled={this.replayRunning()}
                onClick={() => this.playReplay(this.props.replayFileSelected, this.props.replayLoop)}
                disabled={!this.canPlay()}
                data-cy={EXEC_BTN_REPLAY_START}
              >
                START
                PLAY
              </Button>
              <Button
                outlined
                style={styles.button}
                onClick={() => this.triggerReplay(false)}
                onClick={() => this.stopReplay(this.props.replayFileSelected)}
                disabled={!this.replayRunning()}
                data-cy={EXEC_BTN_REPLAY_STOP}
              >
+3 −1
Original line number Diff line number Diff line
@@ -148,7 +148,9 @@ class ExecPageContainer extends Component {
      // TODO: consider showing an alert/toast
      return;
    }
    this.props.changeReplayFilesList(data.replayFiles);
    let replayFiles = data.replayFiles;
    replayFiles.unshift('None');
    this.props.changeReplayFilesList(replayFiles);
  }

  saveScenario(scenarioName) {