blob: 97ea18e88f0b63816b753e782eed0dd731237026 [file] [log] [blame]
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -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 */
Sho SHIMIZU36a8a6e2015-02-13 15:38:45 -080016package org.onosproject.net.intent.impl.phase;
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080017
18import org.onosproject.net.intent.Intent;
Brian O'Connor0e271dc2015-02-04 18:20:25 -080019import org.onosproject.net.intent.IntentData;
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080020import org.onosproject.net.intent.IntentException;
Sho SHIMIZUb0a47d42015-02-19 13:26:30 -080021import org.onosproject.net.intent.impl.IntentProcessor;
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080022import org.slf4j.Logger;
23import org.slf4j.LoggerFactory;
24
Brian O'Connor0e271dc2015-02-04 18:20:25 -080025import java.util.List;
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080026import java.util.Optional;
27
28import static com.google.common.base.Preconditions.checkNotNull;
29
Sho SHIMIZUd3dcaa12015-02-13 13:48:51 -080030/**
31 * Represents a phase where an intent is being compiled.
32 */
Sho SHIMIZU36a8a6e2015-02-13 15:38:45 -080033final class Compiling implements IntentProcessPhase {
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080034
35 private static final Logger log = LoggerFactory.getLogger(Compiling.class);
36
Sho SHIMIZUb0a47d42015-02-19 13:26:30 -080037 private final IntentProcessor processor;
Brian O'Connor0e271dc2015-02-04 18:20:25 -080038 private final IntentData pending;
39 private final IntentData current;
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080040
Sho SHIMIZUb0a47d42015-02-19 13:26:30 -080041 Compiling(IntentProcessor processor, IntentData pending, IntentData current) {
42 this.processor = checkNotNull(processor);
Brian O'Connor0e271dc2015-02-04 18:20:25 -080043 this.pending = checkNotNull(pending);
44 this.current = current;
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080045 }
46
47 @Override
Sho SHIMIZU36a8a6e2015-02-13 15:38:45 -080048 public Optional<IntentProcessPhase> execute() {
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080049 try {
Brian O'Connor0e271dc2015-02-04 18:20:25 -080050 List<Intent> installables = (current != null) ? current.installables() : null;
Sho SHIMIZUb0a47d42015-02-19 13:26:30 -080051 pending.setInstallables(processor.compile(pending.intent(), installables));
52 return Optional.of(new InstallCoordinating(processor, pending, current));
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080053 } catch (IntentException e) {
Sho SHIMIZU877ec2c2015-02-09 12:50:36 -080054 log.debug("Unable to compile intent {} due to: {}", pending.intent(), e);
55 return Optional.of(new CompilingFailed(pending));
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080056 }
57 }
Sho SHIMIZUb0a47d42015-02-19 13:26:30 -080058
Sho SHIMIZU5cb438e2015-02-04 13:46:00 -080059}