(f *model.Function)
| 193 | } |
| 194 | |
| 195 | func (fm *functionManagerImpl) StartFunction(f *model.Function) error { // TODO: Shouldn't use pointer here |
| 196 | if err := f.Validate(); err != nil { |
| 197 | return err |
| 198 | } |
| 199 | fm.functionsLock.Lock() |
| 200 | if _, exist := fm.functions[GetNamespacedName(f.Namespace, f.Name)]; exist { |
| 201 | fm.functionsLock.Unlock() |
| 202 | return common.ErrorFunctionExists |
| 203 | } |
| 204 | fm.functions[GetNamespacedName(f.Namespace, f.Name)] = make([]api.FunctionInstance, f.Replicas) |
| 205 | fm.functionsLock.Unlock() |
| 206 | funcCtx := fm.createFuncCtx() |
| 207 | for i := int32(0); i < f.Replicas; i++ { |
| 208 | runtimeType := f.Runtime.Type |
| 209 | |
| 210 | instanceLogger := fm.log.SubLogger("functionName", f.Name, "instanceIndex", int(i), "runtimeType", runtimeType) |
| 211 | instance := fm.options.instanceFactory.NewFunctionInstance(f, funcCtx, i, instanceLogger) |
| 212 | fm.functionsLock.Lock() |
| 213 | fm.functions[GetNamespacedName(f.Namespace, f.Name)][i] = instance |
| 214 | fm.functionsLock.Unlock() |
| 215 | runtimeFactory, err := fm.getRuntimeFactory(runtimeType) |
| 216 | if err != nil { |
| 217 | return err |
| 218 | } |
| 219 | var sources []<-chan contube.Record |
| 220 | for _, t := range f.Sources { |
| 221 | sourceFactory, err := fm.getTubeFactory(&t) |
| 222 | if err != nil { |
| 223 | return nil |
| 224 | } |
| 225 | sourceChan, err := sourceFactory.NewSourceTube(instance.Context(), t.Config) |
| 226 | if err != nil { |
| 227 | return fmt.Errorf("failed to create source event queue: %w", err) |
| 228 | } |
| 229 | sources = append(sources, sourceChan) |
| 230 | } |
| 231 | sinkFactory, err := fm.getTubeFactory(&f.Sink) |
| 232 | if err != nil { |
| 233 | return nil |
| 234 | } |
| 235 | sink, err := sinkFactory.NewSinkTube(instance.Context(), f.Sink.Config) |
| 236 | if err != nil { |
| 237 | return fmt.Errorf("failed to create sink event queue: %w", err) |
| 238 | } |
| 239 | |
| 240 | runtime, err := runtimeFactory.NewFunctionRuntime(instance) |
| 241 | if err != nil { |
| 242 | return fmt.Errorf("failed to create runtime: %w", err) |
| 243 | } |
| 244 | |
| 245 | go instance.Run(runtime, sources, sink) |
| 246 | } |
| 247 | return nil |
| 248 | } |
| 249 | |
| 250 | func (fm *functionManagerImpl) DeleteFunction(namespace, name string) error { |
| 251 | fm.functionsLock.Lock() |
nothing calls this directly
no test coverage detected