Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opera target view #246

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
96da03d
use exp version
Haishi2016 Apr 15, 2024
c99c1d4
go mod tidy
Haishi2016 Apr 15, 2024
32cfa10
Merge branch 'main' into experimental
Haishi2016 Apr 17, 2024
09decb5
merge main
Haishi2016 Apr 18, 2024
4a96738
commit to experimental branch
Haishi2016 Apr 18, 2024
b51cf99
fix update target result (#227)
msftcoderdjw Apr 18, 2024
9039246
[API] Merge ADO changes to OSS (#220)
msftcoderdjw Apr 20, 2024
c492ff7
opera target view
Haishi2016 May 2, 2024
c810af0
remove Docker check; remove 'v' prefix of version parameter (#228)
Haishi2016 Apr 26, 2024
b2cf925
[K8S] Merge ADO changes to OSS (#233)
msftcoderdjw Apr 26, 2024
02bfa81
Support device in non-default namespace (#238)
RemindD May 1, 2024
4504f60
mo mod tidy on maestro (#244)
Haishi2016 May 2, 2024
9d44b8b
Remove spec.name in catalog/instance/campaign/activation (#242)
msftcoderdjw May 6, 2024
f6b5ee2
Adomerge packages (#237)
iwangjintian May 7, 2024
3cb5392
Use BOT_USER (eclipse-symphoy-bot) to checkout, commit, push changes …
msftcoderdjw May 7, 2024
952f021
Bump version to 0.48.23
actions-user May 8, 2024
5d414bd
Remove CatalogSpec.SiteId (#236)
RemindD May 8, 2024
22130ea
Correctly setup commit user and email in release workflow (#249)
netomi May 8, 2024
9b8d91f
add experimental notice
Haishi2016 Apr 18, 2024
48e9cab
experimental feature table
Haishi2016 Apr 19, 2024
7ba255c
experimental
Haishi2016 Apr 24, 2024
1b69e4b
Proxy processor (#229)
Haishi2016 May 10, 2024
fb33b80
remove proxy changes
Haishi2016 May 13, 2024
072b08a
re-generate artifacts
Haishi2016 May 13, 2024
7f078cd
remove version.txt from branch
Haishi2016 May 13, 2024
164238b
restore version.txt from main branch
Haishi2016 May 13, 2024
b1a9cfe
add statusMessage to show user-friendly display (#255)
msftcoderdjw May 14, 2024
4b67ef1
keep up with main
Haishi2016 May 15, 2024
fdb1ac6
merge conflict
Haishi2016 May 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion api/pkg/apis/v1alpha1/managers/stage/stage-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ func (t *TaskResult) GetError() error {
switch sv := v.(type) {
case v1alpha2.State:
break
case float64:
Copy link
Contributor

@msftcoderdjw msftcoderdjw May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious in which case, when will we get float64 status?

state := v1alpha2.State(int(sv))
stateValue := reflect.ValueOf(state)
if stateValue.Type() != reflect.TypeOf(v1alpha2.State(0)) {
return fmt.Errorf("invalid state %v", sv)
}
t.Outputs["__status"] = state
case int:
state := v1alpha2.State(sv)
stateValue := reflect.ValueOf(state)
Expand Down Expand Up @@ -355,6 +362,7 @@ func (s *StageManager) HandleDirectTriggerEvent(ctx context.Context, triggerData
status.Status = v1alpha2.Done
status.StatusMessage = v1alpha2.Done.String()
status.IsActive = false

return status
}
func carryOutPutsToErrorStatus(outputs map[string]interface{}, err error, site string) map[string]interface{} {
Expand Down Expand Up @@ -578,7 +586,6 @@ func (s *StageManager) HandleTriggerEvent(ctx context.Context, campaign model.Ca
var outputs map[string]interface{}
var pause bool
outputs, pause, err = provider.(stage.IStageProvider).Process(ctx, *s.Manager.Context, inputCopy)

if pause {
pauseRequested = true
}
Expand Down
2 changes: 1 addition & 1 deletion api/pkg/apis/v1alpha1/model/campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type ActivationState struct {
Spec *ActivationSpec `json:"spec,omitempty"`
Status *ActivationStatus `json:"status,omitempty"`
}

type StageSpec struct {
Name string `json:"name,omitempty"`
Contexts string `json:"contexts,omitempty"`
Expand Down Expand Up @@ -63,7 +64,6 @@ func (s StageSpec) DeepEquals(other IDeepEquals) (bool, error) {
if !reflect.DeepEqual(s.Schedule, otherS.Schedule) {
return false, nil
}

return true, nil
}

Expand Down
25 changes: 24 additions & 1 deletion coa/pkg/apis/v1alpha2/bindings/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,30 @@ func wrapAsHTTPHandler(endpoint v1alpha2.Endpoint, handler v1alpha2.COAHandler)
}
reqCtx.SetContentType(resp.ContentType)
reqCtx.SetBody(resp.Body)
reqCtx.SetStatusCode(int(resp.State))
reqCtx.SetStatusCode(toHttpState(resp.State))
}
}
}

func toHttpState(state v1alpha2.State) int {
switch state {
case v1alpha2.OK:
return fasthttp.StatusOK
case v1alpha2.Accepted:
return fasthttp.StatusAccepted
case v1alpha2.BadRequest:
return fasthttp.StatusBadRequest
case v1alpha2.Unauthorized:
return fasthttp.StatusUnauthorized
case v1alpha2.NotFound:
return fasthttp.StatusNotFound
case v1alpha2.MethodNotAllowed:
return fasthttp.StatusMethodNotAllowed
case v1alpha2.Conflict:
return fasthttp.StatusConflict
case v1alpha2.InternalError:
return fasthttp.StatusInternalServerError
default:
return fasthttp.StatusInternalServerError
}
}
21 changes: 14 additions & 7 deletions coa/pkg/apis/v1alpha2/bindings/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ func TestHTTPEcho(t *testing.T) {
Version: "v1",
Handler: func(c v1alpha2.COARequest) v1alpha2.COAResponse {
return v1alpha2.COAResponse{
Body: []byte("Hi there!!"),
Body: []byte("Hi there!!"),
State: v1alpha2.OK,
}
},
},
Expand All @@ -103,7 +104,8 @@ func TestHTTPEcho(t *testing.T) {
Version: "v1",
Handler: func(c v1alpha2.COARequest) v1alpha2.COAResponse {
return v1alpha2.COAResponse{
Body: []byte("Hi " + c.Parameters["name"] + "!!"),
Body: []byte("Hi " + c.Parameters["name"] + "!!"),
State: v1alpha2.OK,
}
},
},
Expand All @@ -114,7 +116,8 @@ func TestHTTPEcho(t *testing.T) {
Parameters: []string{"name"},
Handler: func(c v1alpha2.COARequest) v1alpha2.COAResponse {
return v1alpha2.COAResponse{
Body: []byte("Hi " + c.Parameters["__name"] + "!!!"),
Body: []byte("Hi " + c.Parameters["__name"] + "!!!"),
State: v1alpha2.OK,
}
},
},
Expand All @@ -129,7 +132,8 @@ func TestHTTPEcho(t *testing.T) {
Metadata: map[string]string{
"key": value,
},
Body: []byte("Hi " + value + "!!!!"),
Body: []byte("Hi " + value + "!!!!"),
State: v1alpha2.OK,
}
},
},
Expand Down Expand Up @@ -188,7 +192,8 @@ func TestHTTPEchoWithTLS(t *testing.T) {
Version: "v1",
Handler: func(c v1alpha2.COARequest) v1alpha2.COAResponse {
return v1alpha2.COAResponse{
Body: []byte("Hi there!!"),
Body: []byte("Hi there!!"),
State: v1alpha2.OK,
}
},
},
Expand Down Expand Up @@ -340,12 +345,14 @@ func TestHTTPEchoWithPipeline(t *testing.T) {
switch c.Method {
case fasthttp.MethodGet:
return v1alpha2.COAResponse{
Body: []byte("Hi there!!"),
Body: []byte("Hi there!!"),
State: v1alpha2.OK,
}
case fasthttp.MethodPost:
reqBody := string(c.Body)
return v1alpha2.COAResponse{
Body: []byte(fmt.Sprintf("Hi %s!!", reqBody)),
Body: []byte(fmt.Sprintf("Hi %s!!", reqBody)),
State: v1alpha2.OK,
}
}
return v1alpha2.COAResponse{}
Expand Down
11 changes: 11 additions & 0 deletions docs/samples/campaigns/counter/activation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: workflow.symphony/v1
kind: Activation
metadata:
name: counter-activation
spec:
campaign: "counter-campaign"
name: "counter-activation"
stage: ""
inputs:
val.init: 10
val: 2
12 changes: 12 additions & 0 deletions docs/samples/campaigns/counter/campaign.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: workflow.symphony/v1
kind: Campaign
metadata:
name: counter-campaign
spec:
firstStage: "counter"
selfDriving: true
stages:
counter:
name: "counter"
provider: "providers.stage.counter"
stageSelector: "${{$if($lt($output(counter,val), 20), counter, '')}}"
9 changes: 9 additions & 0 deletions docs/samples/campaigns/hello-world/activation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: workflow.symphony/v1
kind: Activation
metadata:
name: hello-world-activation
spec:
campaign: "hello-world"
name: "hello-world-activation"
inputs:
foo: "bar"
11 changes: 11 additions & 0 deletions docs/samples/campaigns/hello-world/campaign.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: workflow.symphony/v1
kind: Campaign
metadata:
name: hello-world
spec:
firstStage: "mock"
selfDriving: true
stages:
mock:
name: "mock"
provider: "providers.stage.mock"
37 changes: 37 additions & 0 deletions docs/samples/opera/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Step 1: Build the base image with node.js
FROM node:16-alpine as builder

# Set the working directory in the container
WORKDIR /app

# Copy package.json and package-lock.json
COPY package.json package-lock.json ./

# Install dependencies
RUN npm ci
# Copy the rest of the application code
COPY . .

# Build the application
RUN npm run build

# Step 2: Use a smaller base image for the production environment
FROM node:16-alpine

# Set the working directory in the container
WORKDIR /app

# Install the Next.js production server
RUN npm install next

# Copy the build artifacts from the builder stage
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json

# Expose the port Next.js runs on
EXPOSE 3000

# Command to run the application
CMD ["npm", "start"]
5 changes: 2 additions & 3 deletions docs/samples/opera/app/api/solutions/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { NextResponse } from "next/server"
import {SolutionState} from "../../../../types";
import { getServerSession } from 'next-auth';
import { options } from '../../../auth/[...nextauth]/options';
import { User } from '../../../../types';
import { options } from '../auth/[...nextauth]/options';
import { User } from '../../types';

export async function GET(
request: Request,
Expand Down
40 changes: 40 additions & 0 deletions docs/samples/opera/app/targets/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react'
import { getServerSession } from 'next-auth';
import MultiView from '@/components/MultiView';
import { options } from '../api/auth/[...nextauth]/options';
import {TargetState, User} from '../types';
const getTargets = async () => {
const session = await getServerSession(options);
const symphonyApi = process.env.SYMPHONY_API;
const userObj: User | undefined = session?.user?? undefined;
const res = await fetch( `${symphonyApi}targets/registry`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${userObj?.accessToken}`,
}
});
const data = await res.json();
return data;
}
async function TargetsPage() {
const targets = await getTargets();
const params = {
type: 'targets',
menuItems: [
{
name: 'Add Solution',
href: '/solutions/add',
}
],
views: ['cards', 'table'],
items: targets,
columns: []
}
return (
<div>
<MultiView params={params} />
</div>
);
}

export default TargetsPage;
79 changes: 76 additions & 3 deletions docs/samples/opera/app/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface CatalogSpec {
properties: Record<string, any>;
metadata: Record<string, string>;
parentName: string;
objectRef: ObjectRef;
objectRef?: ObjectRef | null | undefined;
generation: string;
}

Expand All @@ -77,6 +77,79 @@ export interface CatalogState {
status: CatalogStatus;
}

export interface BindingSpec {
role: string;
provider: string;
config: Record<string, string>;
}

export interface TopologySpec {
device: string;
selector: Record<string, string>;
bindings: BindingSpec[];
}

export interface TargetSpec {
displayName: string;
scope: string;
metadata: Record<string, string>;
properties: Record<string, string>;
components: ComponentSpec[];
constraints: string;
topologies: TopologySpec[];
forceRedeploy: boolean;
generation: string;
version: string;
}

export interface ComponentError {
code: string;
message: string;
target: string;
}

export interface TargetError {
code: string;
message: string;
target: string;
details: ComponentError[];
}

export interface ErrorType {
code: string;
message: string;
target: string;
details: TargetError[];
}

export interface ProvisioningStatus{
operationId: string;
status: string;
failureCause: string;
logErrors: boolean;
error: ErrorType;
output: Record<string, string>;
}

export interface DeployableStatus {
properties: Record<string, string>;
ProvisioningStatus: ProvisioningStatus;
lastModified: Date;
}

export interface ObjectMeta {
namespace: string;
name: string;
labels: Record<string, string>;
annotations: Record<string, string>;
}

export interface TargetState {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw in this file, there's still some object like SolutionState which doesn't align new object model. Do we need to fix them?

metadata: ObjectMeta;
spec: TargetSpec;
status: DeployableStatus;
}

export interface SolutionState {
id: string;
namespace: string;
Expand Down Expand Up @@ -160,7 +233,7 @@ export interface User {
email?: string | nulll | undefined;
image?: string | null | undefined;
username?: string;
tokenType: string;
tokenType?: string | null | undefined;
roles?: string[] | undefined;
}

Expand All @@ -172,4 +245,4 @@ export interface Rule {
}
export interface Schema {
rules: Record<string, Rule>;
}
}
Loading
Loading