Skip to content
Permalink
Browse files

Created Prober subproject and setup basic ActionHandler and its unit …

…tests (#133)

* Initial Commit.

* Deleted unfinished features. Added ActionHandler and its Unit Tests.

* Included prober subproject in settings.gradle

* Added Protocol Class and its Basic Unit Tests

* Added Changes Suggested by jianglai

* Fixed Gitignore to take out AutoValue generated code

* Removed AutoValue java files

* Added gitignore within prober

* Removed all generated java

* Final Changes in .gitignore

* Added Ssl and WebWhois Action Handlers and their unit tests in addition to the ProbingAction class

* Fixed build.gradle changes requested

* Removed Files irrelevant to current pull request

* Minor fixes to ActionHandler, as responded in comments, removed package-info, and updated settings.gradle

* Fully Updated ActionHandler (missing updated JavaDoc)

* Added changed Protocol and both Inbound and Outbound Markers

* Removed AutoVaue ignore clause from .gitignore

* removed unneccessary dependencies in build.gradle

* Fixed Javadoc and comments for ActionHandler

* Fixed comments and JavaDoc on other files

* EOL added

* Removed Unnecessary Files

* fixed .gradle files styles

* Merge remote-tracking branch 'upstream/master'

* Removed outbound message from ActionHandler's fields and renamed Marker Interfaces

* Fixed javadoc for Marker Interfaced

* Modified Comments on ActionHandler

* Removed LocalAddress from Protocol

* Fixed Travis Build Issues
  • Loading branch information...
Sanger2000 committed Jul 16, 2019
1 parent c120746 commit 0e9b75e5e94729ff8d7e535794d102cf6d9b1937
@@ -0,0 +1 @@
out/
@@ -0,0 +1,49 @@
// Copyright 2019 The Nomulus Authors. 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.

apply plugin: 'java'

createUberJar('deployJar', 'prober', 'google.registry.monitoring.blackbox.Prober')

dependencies {
def deps = rootProject.dependencyMap

compile deps['com.google.auto.value:auto-value-annotations']
compile deps['com.google.dagger:dagger']
compile deps['com.google.flogger:flogger']
compile deps['com.google.guava:guava']
compile deps['io.netty:netty-buffer']
compile deps['io.netty:netty-codec-http']
compile deps['io.netty:netty-codec']
compile deps['io.netty:netty-common']
compile deps['io.netty:netty-handler']
compile deps['io.netty:netty-transport']
compile deps['javax.inject:javax.inject']

runtime deps['com.google.flogger:flogger-system-backend']
runtime deps['com.google.auto.value:auto-value']
runtime deps['io.netty:netty-tcnative-boringssl-static']

testCompile deps['com.google.truth:truth']
testCompile deps['junit:junit']
testCompile deps['org.mockito:mockito-core']
testCompile project(':third_party')

// Include auto-value in compile until nebula-lint understands
// annotationProcessor
annotationProcessor deps['com.google.auto.value:auto-value']
testAnnotationProcessor deps['com.google.auto.value:auto-value']
annotationProcessor deps['com.google.dagger:dagger-compiler']
testAnnotationProcessor deps['com.google.dagger:dagger-compiler']
}
@@ -0,0 +1,58 @@
// Copyright 2019 The Nomulus Authors. 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 google.registry.monitoring.blackbox;

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import io.netty.channel.ChannelHandler;
import javax.inject.Provider;

/**
* {@link AutoValue} class that stores all unchanged variables necessary for type of connection
*/
@AutoValue
public abstract class Protocol {

abstract String name();

public abstract int port();

/** The {@link ChannelHandler} providers to use for the protocol, in order. */
abstract ImmutableList<Provider<? extends ChannelHandler>> handlerProviders();

/** Boolean that notes if connection associated with Protocol is persistent.*/
abstract boolean persistentConnection();

public abstract Builder toBuilder();

public static Builder builder() {
return new AutoValue_Protocol.Builder();
}

@AutoValue.Builder
public static abstract class Builder {

public abstract Builder name(String value);

public abstract Builder port(int num);

public abstract Builder handlerProviders(ImmutableList<Provider<? extends ChannelHandler>> providers);

public abstract Builder persistentConnection(boolean value);

public abstract Protocol build();
}
}

@@ -0,0 +1,74 @@
// Copyright 2019 The Nomulus Authors. 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 google.registry.monitoring.blackbox.handlers;

import com.google.common.flogger.FluentLogger;
import google.registry.monitoring.blackbox.messages.InboundMessageType;
import google.registry.monitoring.blackbox.messages.OutboundMessageType;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;

/**
*Superclass of all {@link ChannelHandler}s placed at end of channel pipeline
*
* <p> {@code ActionHandler} inherits from {@link SimpleChannelInboundHandler< InboundMessageType >}, as it should only be passed in
* messages that implement the {@link InboundMessageType} interface. </p>
*
* <p> The {@code ActionHandler} skeleton exists for a few main purposes. First, it returns a {@link ChannelPromise},
* which informs the {@link ProbingAction} in charge that a response has been read. Second, it stores the {@link OutboundMessageType}
* passed down the pipeline, so that subclasses can use that information for their own processes. Lastly, with any exception
* thrown, the connection is closed, and the ProbingAction governing this channel is informed of the error. Subclasses
* specify further work to be done for specific kinds of channel pipelines. </p>
*/
public abstract class ActionHandler extends SimpleChannelInboundHandler<InboundMessageType> {

private static final FluentLogger logger = FluentLogger.forEnclosingClass();

protected ChannelPromise finished;

/** Takes in {@link OutboundMessageType} type and saves for subclasses. Then returns initialized {@link ChannelPromise}*/
public ChannelFuture getFuture() {
return finished;
}

/** Initializes new {@link ChannelPromise} */
@Override
public void handlerAdded(ChannelHandlerContext ctx) {
//Once handler is added to channel pipeline, initialize channel and future for this handler
finished = ctx.newPromise();
}

@Override
public void channelRead0(ChannelHandlerContext ctx, InboundMessageType inboundMessage) throws Exception {
//simply marks finished as success
finished.setSuccess();
}

/** Logs the channel and pipeline that caused error, closes channel, then informs {@link ProbingAction} listeners of error */
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
logger.atSevere().withCause(cause).log(String.format(
"Attempted Action was unsuccessful with channel: %s, having pipeline: %s",
ctx.channel().toString(),
ctx.channel().pipeline().toString()));

finished.setFailure(cause);
ChannelFuture closedFuture = ctx.channel().close();
closedFuture.addListener(f -> logger.atInfo().log("Unsuccessful channel connection closed"));
}
}

@@ -0,0 +1,21 @@
// Copyright 2019 The Nomulus Authors. 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 google.registry.monitoring.blackbox.messages;

/**
* Marker Interface that is implemented by all classes that serve as {@code inboundMessages} in channel pipeline
*/
public interface InboundMessageType {}

@@ -0,0 +1,21 @@
// Copyright 2019 The Nomulus Authors. 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 google.registry.monitoring.blackbox.messages;

/**
* Marker Interface that is implemented by all classes that serve as {@code outboundMessages} in channel pipeline
*/
public interface OutboundMessageType {}

@@ -28,6 +28,7 @@ if (pluginsUrl) {
rootProject.name = 'nomulus'

include 'core'
include 'prober'
include 'proxy'
include 'third_party'
include 'util'

0 comments on commit 0e9b75e

Please sign in to comment.
You can’t perform that action at this time.