Skip to content

Commit c137be1

Browse files
committed
[core] If needed, RESET before environment teardown
1 parent 70ed8d5 commit c137be1

3 files changed

Lines changed: 80 additions & 14 deletions

File tree

core/environment/transition.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ func MakeTransition(taskman *task.Manager, optype pb.ControlEnvironmentRequest_O
4545
return NewStartActivityTransition(taskman)
4646
case pb.ControlEnvironmentRequest_STOP_ACTIVITY:
4747
return NewStopActivityTransition(taskman)
48-
case pb.ControlEnvironmentRequest_EXIT:
49-
fallthrough
48+
case pb.ControlEnvironmentRequest_RESET:
49+
return NewResetTransition(taskman)
5050
case pb.ControlEnvironmentRequest_GO_ERROR:
5151
fallthrough
5252
case pb.ControlEnvironmentRequest_NOOP:
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* === This file is part of ALICE O² ===
3+
*
4+
* Copyright 2018 CERN and copyright holders of ALICE O².
5+
* Author: Teo Mrnjavac <teo.mrnjavac@cern.ch>
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
* In applying this license CERN does not waive the privileges and
21+
* immunities granted to it by virtue of its status as an
22+
* Intergovernmental Organization or submit itself to any jurisdiction.
23+
*/
24+
25+
package environment
26+
27+
import (
28+
"errors"
29+
"github.com/AliceO2Group/Control/core/task"
30+
)
31+
32+
func NewResetTransition(taskman *task.Manager) Transition {
33+
return &ResetTransition{
34+
baseTransition: baseTransition{
35+
name: "RESET",
36+
taskman: taskman,
37+
},
38+
}
39+
}
40+
41+
type ResetTransition struct {
42+
baseTransition
43+
}
44+
45+
func (t ResetTransition) do(env *Environment) (err error) {
46+
if env == nil {
47+
return errors.New("cannot transition in NIL environment")
48+
}
49+
50+
err = t.taskman.TransitionTasks(
51+
env.Id().Array(),
52+
env.Workflow().GetTasks(),
53+
task.CONFIGURED.String(),
54+
task.RESET.String(),
55+
task.STANDBY.String(),
56+
)
57+
if err != nil {
58+
return
59+
}
60+
61+
return
62+
}

core/server.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,21 @@
2626
package core
2727

2828
import (
29+
"fmt"
30+
"runtime"
31+
"time"
32+
2933
"golang.org/x/net/context"
30-
"google.golang.org/grpc"
34+
"google.golang.org/grpc"
3135

36+
"github.com/AliceO2Group/Control/core/environment"
3237
"github.com/AliceO2Group/Control/core/protos"
33-
"google.golang.org/grpc/reflection"
34-
"github.com/mesos/mesos-go/api/v1/lib/extras/store"
35-
"runtime"
36-
"fmt"
37-
"google.golang.org/grpc/status"
38-
"google.golang.org/grpc/codes"
3938
"github.com/looplab/fsm"
39+
"github.com/mesos/mesos-go/api/v1/lib/extras/store"
4040
"github.com/pborman/uuid"
41-
"time"
42-
"github.com/AliceO2Group/Control/core/environment"
41+
"google.golang.org/grpc/codes"
42+
"google.golang.org/grpc/reflection"
43+
"google.golang.org/grpc/status"
4344
)
4445

4546

@@ -269,9 +270,12 @@ func (m *RpcServer) DestroyEnvironment(cxt context.Context, req *pb.DestroyEnvir
269270
return nil, status.Newf(codes.FailedPrecondition, "cannot destroy environment in state %s", env.CurrentState()).Err()
270271
}
271272

272-
err = env.TryTransition(environment.MakeTransition(m.state.taskman, pb.ControlEnvironmentRequest_EXIT))
273-
if err != nil {
274-
return &pb.DestroyEnvironmentReply{}, status.New(codes.Internal, err.Error()).Err()
273+
// This might transition to STANDBY if needed, of do nothing if we're already there
274+
if env.CurrentState() == "CONFIGURED" {
275+
err = env.TryTransition(environment.MakeTransition(m.state.taskman, pb.ControlEnvironmentRequest_RESET))
276+
if err != nil {
277+
return &pb.DestroyEnvironmentReply{}, status.New(codes.Internal, err.Error()).Err()
278+
}
275279
}
276280

277281
err = m.state.environments.TeardownEnvironment(env.Id())

0 commit comments

Comments
 (0)