blob: 9e27070e98e5f8b49d8f05bc0e382011ad802d39 [file] [log] [blame]
Sho SHIMIZUee2aa652015-02-25 18:56:43 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.net.intent.impl.phase;
17
18import org.onosproject.net.intent.Intent;
19import org.onosproject.net.intent.IntentData;
Ray Milkeyfd7931d2015-03-30 13:58:38 -070020import org.onosproject.net.intent.IntentException;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080021import org.onosproject.net.intent.impl.IntentProcessor;
Ray Milkeyfd7931d2015-03-30 13:58:38 -070022import org.slf4j.Logger;
23import org.slf4j.LoggerFactory;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080024
25import java.util.List;
26import java.util.Optional;
27
28import static com.google.common.base.Preconditions.checkNotNull;
29
30/**
31 * Represents a phase where an intent is being recompiled.
32 */
33class Recompiling implements IntentProcessPhase {
34
Ray Milkeyfd7931d2015-03-30 13:58:38 -070035 private static final Logger log = LoggerFactory.getLogger(Recompiling.class);
36
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080037 private final IntentProcessor processor;
38 private final IntentData data;
39 private final IntentData stored;
40
41 /**
42 * Creates a intent recompiling phase.
43 *
44 * @param processor intent processor that does work for recompiling
45 * @param data intent data containing an intent to be recompiled
46 * @param stored intent data stored in the store
47 */
48 Recompiling(IntentProcessor processor, IntentData data, IntentData stored) {
49 this.processor = checkNotNull(processor);
50 this.data = checkNotNull(data);
51 this.stored = checkNotNull(stored);
52 }
53
54 @Override
55 public Optional<IntentProcessPhase> execute() {
Ray Milkeyfd7931d2015-03-30 13:58:38 -070056 try {
57 List<Intent> compiled = processor.compile(data.intent(), stored.installables());
58 data.setInstallables(compiled);
59 return Optional.of(new Installing(processor, data, stored));
60 } catch (IntentException e) {
61 log.debug("Unable to recompile intent {} due to: {}", data.intent(), e);
62 // FIXME we need to removed orphaned flows and deallocate resources
63 return Optional.of(new CompileFailed(data));
64 }
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080065 }
66}