Skip to content

Commit

Permalink
[core,shell] run shell components in core and remote shell
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog authored and John-John Tedro committed Sep 16, 2015
1 parent 04f9896 commit 7b0497f
Show file tree
Hide file tree
Showing 64 changed files with 1,695 additions and 945 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
dependency-reduced-pom.xml
target
*.log
.*.un~
*~
.*.swp
*.pyc
.classpath
.project
.settings
bin
/*.json
/*.png
/*.log
/*.gz
.*
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.spotify.heroic;

public interface HeroicCoreInjector {
public <T> T inject(T instance);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.spotify.heroic.shell;

import java.io.IOException;
import java.util.List;

import lombok.Data;
import eu.toolchain.serializer.SerialReader;
import eu.toolchain.serializer.SerialWriter;
import eu.toolchain.serializer.Serializer;
import eu.toolchain.serializer.SerializerFramework;


@Data
public class CommandDefinition {
final String name;
final List<String> aliases;
final String usage;

static Serializer<CommandDefinition> serializer(SerializerFramework s) {
return new Serializer<CommandDefinition>() {
final Serializer<String> string = s.string();
final Serializer<List<String>> aliases = s.list(s.string());

@Override
public void serialize(SerialWriter buffer, CommandDefinition value) throws IOException {
this.string.serialize(buffer, value.name);
this.aliases.serialize(buffer, value.aliases);
this.string.serialize(buffer, value.usage);
}

@Override
public CommandDefinition deserialize(SerialReader buffer) throws IOException {
final String name = this.string.deserialize(buffer);
final List<String> aliases = this.aliases.deserialize(buffer);
final String usage = this.string.deserialize(buffer);
return new CommandDefinition(name, aliases, usage);
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.spotify.heroic.shell;

import java.util.List;

public interface CoreInterface {
public CoreShellInterface setup(ShellInterface shell) throws Exception;

public List<CommandDefinition> getCommands() throws Exception;

public void shutdown() throws Exception;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.spotify.heroic.shell;

import java.io.PrintWriter;
import java.util.List;

import eu.toolchain.async.AsyncFuture;

public interface CoreShellInterface {
public AsyncFuture<Void> command(List<String> command, PrintWriter out) throws Exception;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.spotify.heroic.shell;

public interface CoreShellTaskDefinition {
TaskDefinition setup(ShellInterface shell, TaskContext ctx);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.spotify.heroic.shell;

import java.util.List;

import com.spotify.heroic.HeroicCoreInjector;

public interface CoreTaskDefinition {
String name();

List<String> aliases();

List<String> names();

String usage();

CoreShellTaskDefinition setup(HeroicCoreInjector core) throws Exception;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.spotify.heroic.shell;


public interface ShellInterface {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


public interface ShellTask {
public ShellTaskParams params();
public TaskParameters params();

public AsyncFuture<Void> run(PrintWriter out, ShellTaskParams params) throws Exception;
public AsyncFuture<Void> run(PrintWriter out, TaskParameters params) throws Exception;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.spotify.heroic.shell;


public interface TaskContext {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.spotify.heroic.shell;

import java.io.PrintWriter;

import eu.toolchain.async.AsyncFuture;

public interface TaskDefinition {
TaskParameters params();

AsyncFuture<Void> run(PrintWriter out, TaskParameters params) throws Exception;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2015 Spotify AB.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.spotify.heroic.shell;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface TaskName {
String value() default "";

String[] aliases() default {};
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.spotify.heroic.shell;


public interface ShellTaskParams {
public interface TaskParameters {
public String config();

public boolean help();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ShellTaskUsage {
public @interface TaskUsage {
String value() default "";
}
8 changes: 0 additions & 8 deletions heroic-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,11 @@
<dependency>
<groupId>args4j</groupId>
<artifactId>args4j</artifactId>
<version>2.0.29</version>
</dependency>

<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.8.2</version>
</dependency>

<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>2.12</version>
</dependency>

<!-- used for logging -->
Expand Down
12 changes: 6 additions & 6 deletions heroic-core/src/main/java/com/spotify/heroic/HeroicConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import com.spotify.heroic.ingestion.IngestionModule;
import com.spotify.heroic.metadata.MetadataManagerModule;
import com.spotify.heroic.metric.MetricManagerModule;
import com.spotify.heroic.shell.HeroicShellServerModule;
import com.spotify.heroic.shell.ShellServerModule;
import com.spotify.heroic.suggest.SuggestManagerModule;

@RequiredArgsConstructor
Expand All @@ -60,7 +60,7 @@ public class HeroicConfig {
private final HttpClientManagerModule client;
private final IngestionModule ingestion;
private final List<ConsumerModule> consumers;
private final HeroicShellServerModule shellServer;
private final ShellServerModule shellServer;

@JsonCreator
public HeroicConfig(@JsonProperty("host") String host, @JsonProperty("port") Integer port,
Expand All @@ -72,7 +72,7 @@ public HeroicConfig(@JsonProperty("host") String host, @JsonProperty("port") Int
@JsonProperty("client") HttpClientManagerModule client,
@JsonProperty("ingestion") IngestionModule ingestion,
@JsonProperty("consumers") List<ConsumerModule> consumers,
@JsonProperty("shellServer") HeroicShellServerModule shellServer) {
@JsonProperty("shellServer") ShellServerModule shellServer) {
this.host = Optional.fromNullable(host).or(DEFAULT_HOST);
this.port = Optional.fromNullable(port).or(DEFAULT_PORT);
this.refreshClusterSchedule = Optional.fromNullable(refreshClusterSchedule)
Expand All @@ -85,7 +85,7 @@ public HeroicConfig(@JsonProperty("host") String host, @JsonProperty("port") Int
this.cache = Optional.fromNullable(cache).or(AggregationCacheModule.defaultSupplier());
this.ingestion = Optional.fromNullable(ingestion).or(IngestionModule.defaultSupplier());
this.consumers = Optional.fromNullable(consumers).or(DEFAULT_CONSUMERS);
this.shellServer = Optional.fromNullable(shellServer).or(HeroicShellServerModule::defaultSupplier);
this.shellServer = Optional.fromNullable(shellServer).or(ShellServerModule::defaultSupplier);
}

public static Builder builder() {
Expand All @@ -104,7 +104,7 @@ public static class Builder {
private HttpClientManagerModule client;
private IngestionModule ingestion;
private List<ConsumerModule> consumers;
private HeroicShellServerModule shellServer;
private ShellServerModule shellServer;

public Builder host(String host) {
this.host = host;
Expand Down Expand Up @@ -161,7 +161,7 @@ public Builder consumers(List<ConsumerModule> consumers) {
return this;
}

public Builder shellServer(HeroicShellServerModule shellServer) {
public Builder shellServer(ShellServerModule shellServer) {
this.shellServer = shellServer;
return this;
}
Expand Down
17 changes: 12 additions & 5 deletions heroic-core/src/main/java/com/spotify/heroic/HeroicCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
* @author udoprog
*/
@Slf4j
public class HeroicCore {
public class HeroicCore implements HeroicCoreInjector {
static final List<Class<?>> DEFAULT_MODULES = ImmutableList.of();
static final List<HeroicConfigurator> DEFAULT_CONFIGURATORS = ImmutableList.of();
static final boolean DEFAULT_SERVER = true;
Expand Down Expand Up @@ -249,6 +249,8 @@ private void doStart() throws Exception {
configurator.setup(primary);
}

this.primary.set(primary);

try {
startLifeCycles(primary);
} catch (Exception e) {
Expand Down Expand Up @@ -279,8 +281,6 @@ public void onStartup(Context context) throws Exception {
}
});

this.primary.set(primary);

lifecycle.start();
log.info("Heroic was successfully started!");
}
Expand All @@ -290,11 +290,12 @@ public void onStartup(Context context) throws Exception {
*
* @param injectee Object to inject fields on.
*/
@Override
public <T> T inject(T injectee) {
final Injector primary = this.primary.get();

if (primary == null) {
throw new IllegalStateException("heroic has not started");
throw new IllegalStateException("primary injector not available");
}

primary.injectMembers(injectee);
Expand Down Expand Up @@ -518,6 +519,12 @@ private Injector primaryInjector(final HeroicConfig config, final Injector early

// register root components.
modules.add(new AbstractModule() {
@Provides
@Singleton
public HeroicCore core() {
return HeroicCore.this;
}

@Provides
@Singleton
public Set<LifeCycle> lifecycles() {
Expand Down Expand Up @@ -595,7 +602,7 @@ protected void configure() {
modules.add(config.getIngestion());

// shell server module
// modules.add(config.getShellServer());
modules.add(config.getShellServer());

modules.add(new AbstractModule() {
@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.kohsuke.args4j.Option;


public abstract class AbstractShellTaskParams implements ShellTaskParams {
public abstract class AbstractShellTaskParams implements TaskParameters {
@Option(name = "-c", aliases = { "--config" }, usage = "Path to configuration (only used in standalone)", metaVar = "<config>")
public String config;

Expand Down

This file was deleted.

Loading

0 comments on commit 7b0497f

Please sign in to comment.