Skip to content

Commit

Permalink
Merge branch 'main' into users/xingdong/redissidecar
Browse files Browse the repository at this point in the history
  • Loading branch information
RemindD authored May 21, 2024
2 parents 15b9994 + 64a3cc3 commit 07b7147
Show file tree
Hide file tree
Showing 30 changed files with 697 additions and 56 deletions.
7 changes: 7 additions & 0 deletions 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:
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
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 @@ -161,7 +161,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
10 changes: 10 additions & 0 deletions docs/samples/campaigns/counter/activation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: workflow.symphony/v1
kind: Activation
metadata:
name: counter-activation
spec:
campaign: "counter-campaign"
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, '')}}"
8 changes: 8 additions & 0 deletions docs/samples/campaigns/hello-world/activation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: workflow.symphony/v1
kind: Activation
metadata:
name: hello-world-activation
spec:
campaign: "hello-world"
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;
77 changes: 75 additions & 2 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 {
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 Down
39 changes: 39 additions & 0 deletions docs/samples/opera/components/Filter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React, { useState } from 'react';
import { Input, NavbarContent, Button } from '@nextui-org/react';

// Define an interface for the component props
interface FilterProps {
onSelectFilter: (filter: string) => void; // This function takes a string and returns void
}

const Filter: React.FC<FilterProps> = ({ onSelectFilter }) => {
const [selectedFilter, setSelectedFilter] = useState(''); // State to keep track of the filter input

// Function to handle input changes
const handleFilterChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const filter = event.target.value;
setSelectedFilter(filter); // Update selected filter state
onSelectFilter(filter); // Pass filter to parent component
};

// Function to handle filter submission
const handleFilterSubmit = () => {
onSelectFilter(selectedFilter);
};

return (
<NavbarContent>
<Input
isClearable={true}
placeholder="Filter"
value={selectedFilter}
onChange={handleFilterChange}
/>
<Button onClick={handleFilterSubmit}>
Apply
</Button>
</NavbarContent>
);
};

export default Filter;
Loading

0 comments on commit 07b7147

Please sign in to comment.