◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
57 changes: 28 additions & 29 deletions cli/feast/cmd/register.go → cli/feast/cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ import (
"io/ioutil"
"path/filepath"

"github.com/gojektech/feast/go-feast-proto/feast/core"

"feast/cli/feast/pkg/parse"

"github.com/spf13/cobra"
)

// registerCmd represents the register command
var registerCmd = &cobra.Command{
Use: "register [resource] [filepaths...]",
Short: "Register a resource given one or many yaml files.",
Long: `Register a resource from one or multiple yamls.

Valid resources include:
- entity
Expand All @@ -41,17 +40,17 @@ Valid resources include:
- storage

Examples:
- feast register entity entity.yml
- feast register storage storage1.yml storage2.yml
- feast register feature *-feature.yml`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return cmd.Help()
}

if len(args) < 2 {
fmt.Println(args)
return errors.New("invalid number of arguments for register command")
}

initConn()
Expand All @@ -62,75 +61,75 @@ Examples:

for _, fp := range paths {
if isYaml(fp) {
fmt.Printf("Registering %s at %s\n", resource, fp)
regID, err := register(ctx, coreCli, resource, fp)
if err != nil {
return fmt.Errorf("failed to register %s at path %s: %v", resource, fp, err)
}
fmt.Printf("Successfully registered %s %s\n", resource, regID)
}
}
return nil
},
}

func init() {
rootCmd.AddCommand(registerCmd)
}

func register(ctx context.Context, coreCli core.CoreServiceClient, resource string, fileLocation string) (string, error) {
yml, err := ioutil.ReadFile(fileLocation)
if err != nil {
return "", fmt.Errorf("error reading file at %s: %v", fileLocation, err)
}

switch resource {
case "feature":
return registerFeature(ctx, coreCli, yml)
case "featureGroup":
return registerFeatureGroup(ctx, coreCli, yml)
case "entity":
return registerEntity(ctx, coreCli, yml)
case "storage":
return registerStorage(ctx, coreCli, yml)
default:
return "", fmt.Errorf("invalid resource %s: please choose one of [feature, featureGroup, entity, storage]", resource)
}
}

func registerFeature(ctx context.Context, coreCli core.CoreServiceClient, yml []byte) (string, error) {
fs, err := parse.YamlToFeatureSpec(yml)
if err != nil {
return "", err
}
_, err = coreCli.RegisterFeature(ctx, fs)
return fs.GetId(), err
}

func registerFeatureGroup(ctx context.Context, coreCli core.CoreServiceClient, yml []byte) (string, error) {
fgs, err := parse.YamlToFeatureGroupSpec(yml)
if err != nil {
return "", err
}
_, err = coreCli.RegisterFeatureGroup(ctx, fgs)
return fgs.GetId(), err
}

func registerEntity(ctx context.Context, coreCli core.CoreServiceClient, yml []byte) (string, error) {
es, err := parse.YamlToEntitySpec(yml)
if err != nil {
return "", err
}
_, err = coreCli.RegisterEntity(ctx, es)
return es.GetName(), err
}

func registerStorage(ctx context.Context, coreCli core.CoreServiceClient, yml []byte) (string, error) {
ss, err := parse.YamlToStorageSpec(yml)
if err != nil {
return "", err
}
_, err = coreCli.RegisterStorage(ctx, ss)
return ss.GetId(), err
}

Expand Down
5 changes: 2 additions & 3 deletions cli/feast/cmd/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ import (
"fmt"
"io/ioutil"

"feast/cli/feast/pkg/parse"
"feast/cli/feast/pkg/printer"

"github.com/gojektech/feast/go-feast-proto/feast/core"

"github.com/spf13/cobra"
Expand Down
2 changes: 1 addition & 1 deletion cli/feast/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ package cmd
import (
"context"
"errors"
"feast/cli/feast/pkg/util"
"fmt"
"os"
"strings"
"text/tabwriter"

"github.com/gojektech/feast/go-feast-proto/feast/core"

"github.com/golang/protobuf/ptypes/empty"
Expand Down
2 changes: 1 addition & 1 deletion cli/feast/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/spf13/cobra"
)

var version = "0.2.0"

var versionCmd = &cobra.Command{
Use: "version",
Expand Down
2 changes: 1 addition & 1 deletion cli/feast/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package main

import "feast/cli/feast/cmd"

func main() {
cmd.Execute()
Expand Down
2 changes: 1 addition & 1 deletion cli/feast/pkg/printer/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package printer

import (
"feast/cli/feast/pkg/util"
"fmt"
"strings"

"github.com/gojektech/feast/go-feast-proto/feast/core"
)

Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/feast/core/job/ScheduledJobMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

import com.google.common.base.Strings;
import feast.core.dao.JobInfoRepository;
import feast.core.log.AuditLogger;
import feast.core.model.JobInfo;
import feast.core.model.JobStatus;
import feast.core.model.Metrics;
Expand Up @@ -74,9 +76,9 @@ public void pollStatusAndMetrics() {
JobStatus jobStatus = jobMonitor.getJobStatus(jobId);
if (job.getStatus() != jobStatus) {
AuditLogger.log(
"Jobs",
jobId,
"Status Update",
"Job status updated from %s to %s",
job.getStatus(),
jobStatus);
Expand Down
19 changes: 19 additions & 0 deletions core/src/main/java/feast/core/log/Action.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
6 changes: 3 additions & 3 deletions core/src/main/java/feast/core/log/AuditLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public class AuditLogger {
* @param detail additional detail. Supports string formatting.
* @param args arguments to the detail string
*/
public static void log(String resource, String id, String action, String detail, Object... args) {
Map<String, String> map = new TreeMap<>();
map.put("timestamp", new Date().toString());
map.put("resource", resource);
map.put("id", id);
map.put("action", action);
map.put("detail", Strings.lenientFormat(detail, args));
ObjectMessage msg = new ObjectMessage(map);

Expand Down
12 changes: 12 additions & 0 deletions core/src/main/java/feast/core/log/Resource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Loading
Toggle all file notes Toggle all file annotations