Skip to content

Commit

Permalink
Merge pull request #261 from bjwswang/dp
Browse files Browse the repository at this point in the history
feat: impl dataprocessing list api
  • Loading branch information
bjwswang authored Nov 22, 2023
2 parents fe574c5 + ed7e262 commit d0cd5ef
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 1 deletion.
3 changes: 2 additions & 1 deletion graphql-server/go-server/graph/impl/dataprocess.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions graphql-server/go-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/kubeagi/arcadia/graphql-server/go-server/graph/generated"
"github.com/kubeagi/arcadia/graphql-server/go-server/graph/impl"
"github.com/kubeagi/arcadia/graphql-server/go-server/pkg/auth"
"github.com/kubeagi/arcadia/graphql-server/go-server/pkg/dataprocessing"
"github.com/kubeagi/arcadia/graphql-server/go-server/pkg/minio"
"github.com/kubeagi/arcadia/graphql-server/go-server/pkg/oidc"

Expand All @@ -52,6 +53,9 @@ var (
masterURL = flag.String("master-url", "", "k8s master url(required when enable odic)")
clientID = flag.String("client-id", "", "oidc client id(required when enable odic)")
clientSecret = flag.String("client-secret", "", "oidc client secret(required when enable odic)")

// Flags to data-processing server
dataProcessingURL = flag.String("data-processing-url", "http://127.0.0.1:28888", "url to access data processing server")
)

func main() {
Expand All @@ -61,6 +65,9 @@ func main() {
oidc.InitOIDCArgs(*issuerURL, *masterURL, *clientSecret, *clientID)
}

// initialize dataprocessing
dataprocessing.Init(*dataProcessingURL)

srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &impl.Resolver{}}))
srv.AroundFields(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) {
rc := graphql.GetFieldContext(ctx)
Expand Down
66 changes: 66 additions & 0 deletions graphql-server/go-server/pkg/dataprocessing/dataprocessing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Copyright 2023 KubeAGI.
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 dataprocessing

import (
"bytes"
"context"
"encoding/json"
"net/http"
"sync"

"github.com/kubeagi/arcadia/graphql-server/go-server/graph/generated"
)

var (
once sync.Once
url string
)

func Init(dataprocessingURL string) {
once.Do(func() {
url = dataprocessingURL
})
}

func ListDataprocessing(ctx context.Context, obj *generated.DataProcessQuery, input *generated.AllDataProcessListByPageInput) (*generated.PaginatedDataProcessItem, error) {
// prepare http request
jsonParams, err := json.Marshal(input)
if err != nil {
return nil, err
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonParams))
if err != nil {
return nil, err
}

// call dataprocessing server
client := http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()

// parse http response
pagedData := &generated.PaginatedDataProcessItem{}
err = json.NewDecoder(resp.Body).Decode(pagedData)
if err != nil {
return nil, err
}
return pagedData, nil
}
16 changes: 16 additions & 0 deletions graphql-server/go-server/pkg/dataset/dataset.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright 2023 KubeAGI.
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 dataset

import (
Expand Down

0 comments on commit d0cd5ef

Please sign in to comment.