Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
implement aurora scheduler getJobLinks (#707)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlu90 committed May 19, 2016
1 parent d656ecc commit e200e42
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2016 Twitter. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.twitter.heron.scheduler.aurora;

import com.twitter.heron.spi.common.Config;
import com.twitter.heron.spi.common.Context;

public final class AuroraContext extends Context {
public static final String JOB_LINK_TEMPLATE = "heron.scheduler.job.link.template";

private AuroraContext() {
}

public static String getJobLinkTemplate(Config config) {
return config.getStringValue(JOB_LINK_TEMPLATE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.twitter.heron.proto.scheduler.Scheduler;
import com.twitter.heron.spi.common.Config;
import com.twitter.heron.spi.common.Context;
import com.twitter.heron.spi.common.Misc;
import com.twitter.heron.spi.common.PackingPlan;
import com.twitter.heron.spi.scheduler.IScheduler;
import com.twitter.heron.spi.utils.Runtime;
Expand Down Expand Up @@ -83,7 +84,16 @@ public boolean onSchedule(PackingPlan packing) {

@Override
public List<String> getJobLinks() {
return new ArrayList<>();
List<String> jobLinks = new ArrayList<>();

//Only the aurora job page is returned
String jobLinkFormat = AuroraContext.getJobLinkTemplate(config);
if (jobLinkFormat != null && !jobLinkFormat.isEmpty()) {
String jobLink = Misc.substitute(config, jobLinkFormat);
jobLinks.add(jobLink);
}

return jobLinks;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.twitter.heron.scheduler.aurora;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
Expand All @@ -23,13 +24,20 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import com.twitter.heron.proto.scheduler.Scheduler;
import com.twitter.heron.spi.common.Config;
import com.twitter.heron.spi.common.Misc;
import com.twitter.heron.spi.common.PackingPlan;

@RunWith(PowerMockRunner.class)
@PrepareForTest(Misc.class)
public class AuroraSchedulerTest {
private static final String AURORA_PATH = "path.aurora";
private static final String PACKING_PLAN_ID = "packing.plan.id";
Expand Down Expand Up @@ -144,4 +152,25 @@ public void testOnRestart() throws Exception {
Assert.assertTrue(scheduler.onRestart(restartTopologyRequest));
Mockito.verify(controller, Mockito.times(2)).restartJob(containerToRestart);
}

@Test
public void testGetJobLinks() throws Exception {
final String JOB_LINK_FORMAT = "http://go/${CLUSTER}/${ROLE}/${ENVIRON}/${TOPOLOGY}";
final String SUBSTITUTED_JOB_LINK = "http://go/local/heron/test/test_topology";

Config mockConfig = Mockito.mock(Config.class);
Mockito.when(mockConfig.getStringValue(AuroraContext.JOB_LINK_TEMPLATE))
.thenReturn(JOB_LINK_FORMAT);

scheduler.initialize(mockConfig, Mockito.mock(Config.class));

PowerMockito.spy(Misc.class);
PowerMockito.doReturn(SUBSTITUTED_JOB_LINK)
.when(Misc.class, "substitute", mockConfig, JOB_LINK_FORMAT);

List<String> result = scheduler.getJobLinks();

Assert.assertEquals(1, result.size());
Assert.assertTrue(result.get(0).equals(SUBSTITUTED_JOB_LINK));
}
}
4 changes: 4 additions & 0 deletions heron/spi/src/java/com/twitter/heron/spi/common/Misc.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ public static String substitute(Config config, String pathString) {

} else if ("${TOPOLOGY}".equals(elem)) {
list.set(i, Context.topologyName(config));

} else if ("${ENVIRON}".equals(elem)) {
list.set(i, Context.environ(config));

}
}

Expand Down

0 comments on commit e200e42

Please sign in to comment.