Skip to content

Commit

Permalink
[ISSUE #2992] Use new code style for nacos-cmdb module. (#3289)
Browse files Browse the repository at this point in the history
* Use new code style for nacos-cmdb module.

* Check again for nacos-common module.

* Check again for nacos-core module.

* Check again for nacos-naming module.

* skip nacos-test in checkstyle
  • Loading branch information
KomachiSion authored Jul 9, 2020
1 parent 66e6d24 commit bc9861c
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ public <T> HttpRestResult<T> postForm(String url, Header header, Map<String, Str
}

/**
* Execute the HTTP method to the given URI template, writing the given request entity to the request, and
* returns the response as {@link HttpRestResult}.
* Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns
* the response as {@link HttpRestResult}.
*
* @param url url
* @param header http header param
Expand All @@ -311,12 +311,11 @@ public <T> HttpRestResult<T> postForm(String url, Header header, Map<String, Str
* @return {@link HttpRestResult}
* @throws Exception ex
*/
public <T> HttpRestResult<T> exchangeForm(String url, Header header,
Map<String, String> paramValues, Map<String, String> bodyValues, String httpMethod, Type responseType) throws Exception{
public <T> HttpRestResult<T> exchangeForm(String url, Header header, Map<String, String> paramValues,
Map<String, String> bodyValues, String httpMethod, Type responseType) throws Exception {
RequestHttpEntity requestHttpEntity = new RequestHttpEntity(
header.setContentType(MediaType.APPLICATION_FORM_URLENCODED),
Query.newInstance().initParams(paramValues),
bodyValues);
header.setContentType(MediaType.APPLICATION_FORM_URLENCODED),
Query.newInstance().initParams(paramValues), bodyValues);
return execute(url, httpMethod, requestHttpEntity, responseType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@
import com.alibaba.nacos.common.utils.IoUtils;
import com.alibaba.nacos.common.utils.JacksonUtils;
import org.apache.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.lang.reflect.Type;

import org.slf4j.Logger;

/**
* Response handler.
*
Expand Down Expand Up @@ -80,7 +79,7 @@ public static <T> HttpRestResult<T> responseEntityExtractor(HttpClientResponse r
T extractBody = null;
final boolean typeToStr = String.class.toString().equals(type.toString());
if (contentType != null && contentType.startsWith(MediaType.APPLICATION_JSON) && HttpStatus.SC_OK == response
.getStatusCode()) {
.getStatusCode()) {
// When the type is string type and the response contentType is [application/json],
// then it should be serialized as string
if (typeToStr) {
Expand All @@ -92,8 +91,7 @@ public static <T> HttpRestResult<T> responseEntityExtractor(HttpClientResponse r
if (extractBody == null) {
if (!typeToStr) {
LOGGER.error(
"if the response contentType is not [application/json]," +
" only support to java.lang.String");
"if the response contentType is not [application/json]," + " only support to java.lang.String");
throw new NacosDeserializationException(type);
}
extractBody = (T) IoUtils.toString(body, headers.getCharset());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

/**
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
* @author zongtanghu
*/
@FixMethodOrder(value = MethodSorters.NAME_ASCENDING)
public class NotifyCenterTest {

Expand Down Expand Up @@ -99,7 +95,6 @@ public Class<? extends Event> subscribeType() {

ThreadUtils.sleep(5000L);


latch.await(5000L, TimeUnit.MILLISECONDS);

Assert.assertEquals(2, count.get());
Expand Down Expand Up @@ -269,7 +264,6 @@ public Class<? extends Event> subscribeType() {

}


static class SmartEvent1 extends Event {

@Override
Expand All @@ -286,12 +280,6 @@ public long sequence() {
}
}

/**
* One SmartSubscriber can listen serveral Events.
* And then, Notify publish events by Publisher.
*
* @throws Exception
*/
@Test
public void testSeveralEventsPublishedBySinglePublisher() throws Exception {

Expand Down Expand Up @@ -347,19 +335,12 @@ private static class TestSlowEvent1 extends SlowEvent {
private static class TestSlowEvent2 extends SlowEvent {
}

/**
* Two general subscriber can listen two kinds of SlowEvents.
* And then, Notify publish events by SharePublisher.
*
* @throws Exception
*/
@Test
public void testMutipleSlowEventsListenedBySubscriber() throws Exception {

NotifyCenter.registerToSharePublisher(TestSlowEvent1.class);
NotifyCenter.registerToSharePublisher(TestSlowEvent2.class);



final AtomicInteger count1 = new AtomicInteger(0);
final AtomicInteger count2 = new AtomicInteger(0);

Expand Down Expand Up @@ -414,19 +395,12 @@ private static class TestSlowEvent3 extends SlowEvent {
private static class TestSlowEvent4 extends SlowEvent {
}

/**
* One SmartSubscriber can listen serveral SlowEvents.
* And then, Notify publish events by SharePublisher.
*
* @throws Exception
*/
@Test
public void testMutipleSlowEventsListenedBySmartsubscriber() throws Exception {

NotifyCenter.registerToSharePublisher(TestSlowEvent3.class);
NotifyCenter.registerToSharePublisher(TestSlowEvent4.class);


final AtomicInteger count1 = new AtomicInteger(0);
final AtomicInteger count2 = new AtomicInteger(0);

Expand Down Expand Up @@ -478,19 +452,12 @@ private static class TestSlowEvent5 extends SlowEvent {
private static class TestEvent6 extends Event {
}

/**
* One SmartSubscriber can listen mutiple kinds of event: SlowEvent and General Event.
* And then, Notify publish events by SharePublisher and default pusbisher.
*
* @throws Exception
*/
@Test
public void testMutipleKindsEventsCanListenBySmartsubscriber() throws Exception {

NotifyCenter.registerToSharePublisher(TestSlowEvent5.class);
NotifyCenter.registerToPublisher(TestEvent6.class, 1024);


final AtomicInteger count1 = new AtomicInteger(0);
final AtomicInteger count2 = new AtomicInteger(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ private void registerClusterEvent() {
NotifyCenter.registerSubscribe(new Subscribe<InetUtils.IPChangeEvent>() {
@Override
public void onEvent(InetUtils.IPChangeEvent event) {
String oldAddress = event.getOldIp() + ":" + port;
String newAddress = event.getNewIp() + ":" + port;
ServerMemberManager.this.localAddress = newAddress;
ApplicationUtils.setLocalAddress(localAddress);

Member self = ServerMemberManager.this.self;
self.setIp(event.getNewIp());


String oldAddress = event.getOldIp() + ":" + port;
ServerMemberManager.this.serverList.remove(oldAddress);
ServerMemberManager.this.serverList.put(newAddress, self);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

import static com.alibaba.nacos.core.notify.NotifyCenter.RING_BUFFER_SIZE;
Expand Down Expand Up @@ -85,6 +84,7 @@ public synchronized void start() {
}
}

@Override
public long currentEventSize() {
return queue.size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static void touch(File file) throws IOException {
* {@code Path} is associated with the same {@code FileSystem} as the given
* directory.
*
* <p> The details as to how the name of the file is constructed is
* <p>The details as to how the name of the file is constructed is
* implementation dependent and therefore not specified. Where possible
* the {@code prefix} and {@code suffix} are used to construct candidate
* names in the same manner as the {@link
Expand Down Expand Up @@ -452,7 +452,7 @@ public static void decompress(final String sourceFile, final String outputDir, f
* to free internal resources. This can be done by calling the
* {@link org.apache.commons.io.LineIterator#close()} or
* {@link org.apache.commons.io.LineIterator#closeQuietly(org.apache.commons.io.LineIterator)} method.
* <p>
* </p>
* The recommended usage pattern is:
* <pre>
* LineIterator it = FileUtils.lineIterator(file, "UTF-8");
Expand All @@ -468,6 +468,7 @@ public static void decompress(final String sourceFile, final String outputDir, f
* <p>
* If an exception occurs during the creation of the iterator, the
* underlying stream is closed.
* </p>
*
* @param file the file to open for input, must not be <code>null</code>
* @param encoding the encoding to use, <code>null</code> means platform default
Expand Down
12 changes: 6 additions & 6 deletions istio/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>nacos-all</artifactId>
<groupId>com.alibaba.nacos</groupId>
<version>1.3.1-BETA</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>nacos-istio</artifactId>
<packaging>jar</packaging>

<name>nacos-istio ${project.version}</name>
<url>http://nacos.io</url>

<dependencies>
<dependency>
<groupId>junit</groupId>
Expand All @@ -55,7 +55,7 @@
<groupId>${project.groupId}</groupId>
<artifactId>nacos-core</artifactId>
</dependency>

<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
Expand Down Expand Up @@ -90,7 +90,7 @@
<artifactId>netty-common</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down
3 changes: 3 additions & 0 deletions istio/src/main/java/com/alibaba/nacos/istio/IstioApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.istio;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
* Istio starter.
*
* @author nkorange
* @since 1.1.4
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.istio.mcp;


/**
* The collection types supported by Nacos
* The collection types supported by Nacos.
*
* @author nkorange
* @since 1.1.4
*/
public class CollectionTypes {

public static final String SERVICE_ENTRY = "istio/networking/v1alpha3/serviceentries";
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,39 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.istio.mcp;

import com.alibaba.nacos.istio.misc.Loggers;
import io.grpc.*;
import io.grpc.Grpc;
import io.grpc.Metadata;
import io.grpc.ServerCall;
import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptor;
import org.springframework.stereotype.Service;

import java.net.SocketAddress;

/**
* Interceptor for MCP server
* Interceptor for MCP server.
*
* @author nkorange
* @since 1.1.4
*/
@Service
public class McpServerIntercepter implements ServerInterceptor {

private static final String INTERCEPTE_METHOD_NAME = "EstablishResourceStream";

@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call,
Metadata headers,
ServerCallHandler<ReqT, RespT> next) {

public <R, T> ServerCall.Listener<R> interceptCall(ServerCall<R, T> call, Metadata headers,
ServerCallHandler<R, T> next) {

SocketAddress address = call.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR);
String methodName = call.getMethodDescriptor().getFullMethodName();

Loggers.MAIN.info("remote address: {}, method: {}", address, methodName);

return next.startCall(call, headers);
}
}
Loading

0 comments on commit bc9861c

Please sign in to comment.