gorealis v2 refactor (#5)

* Changing default timeout for start maintenance.

* Upgrading dependencies to gorealis v2 and thrift  0.12.0

* Refactored to update to gorealis v2.
This commit is contained in:
Renan DelValle 2018-12-27 11:31:51 -08:00 committed by GitHub
parent ad4dd9606e
commit 6ab5c9334d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1335 changed files with 137431 additions and 61530 deletions

View file

@ -34,5 +34,5 @@ using System.Runtime.InteropServices;
[assembly: Guid("0af10984-40d3-453d-b1e5-421529e8c7e2")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("0.12.0.0")]
[assembly: AssemblyFileVersion("0.12.0.0")]

View file

@ -22,6 +22,7 @@
#include "FacebookService.h"
#include <boost/shared_ptr.hpp>
#include <thrift/server/TServer.h>
#include <thrift/concurrency/Mutex.h>

View file

@ -24,6 +24,7 @@
namespace java com.facebook.fb303
namespace cpp facebook.fb303
namespace perl Facebook.FB303
namespace netcore Facebook.FB303.Test
/**
* Common status reporting mechanism across all services

View file

@ -0,0 +1,5 @@
# Maven Ant tasks Jar details
mvn.ant.task.version=2.1.3
mvn.repo=http://repo1.maven.org/maven2
mvn.ant.task.url=${mvn.repo}/org/apache/maven/maven-ant-tasks/${mvn.ant.task.version}
mvn.ant.task.jar=maven-ant-tasks-${mvn.ant.task.version}.jar

View file

@ -7,9 +7,9 @@
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
@ -26,20 +26,20 @@
<property name="interface.dir" value="${basedir}/../if"/>
<property name="thrift.java.dir" location="${thrift.root}/lib/java"/>
<property name="build.tools.dir" location="${thrift.java.dir}/build/tools/"/>
<property name="thrift_compiler" value="${thrift.root}/compiler/cpp/thrift"/>
<property name="thrift_compiler" value="${thrift.root}/compiler/cpp/thrift"/>
<property file="${basedir}/build.properties"/>
<!-- inherit from the java build file for version and other properties -->
<property file="${thrift.java.dir}/build.properties" />
<property file="${thrift.java.dir}/gradle.properties" />
<property environment="env"/>
<condition property="version" value="${thrift.version}">
<isset property="release"/>
</condition>
<property name="version" value="${thrift.version}-snapshot"/>
<property name="version" value="${thrift.version}-SNAPSHOT"/>
<property name="fb303.final.name" value="${fb303.artifactid}-${version}"/>
<property name="thrift.java.libthrift" value="${thrift.java.dir}/build/libthrift-${version}.jar"/>
<property name="src" value="${basedir}/src"/>
<property name="gen" value="${basedir}/gen-java"/>
@ -74,8 +74,12 @@
<echo message="Building ${fb303.final.name}.jar"/>
<javac destdir="${build.classes.dir}" debug="on">
<classpath>
<pathelement location="${thrift.java.libthrift}"/>
<fileset dir="${thrift.root}/lib/java/build/lib">
<fileset dir="${thrift.java.dir}/build/libs">
<include name="libthrift*.jar" />
<exclude name="libthrift*javadoc.jar" />
<exclude name="libthrift*sources.jar" />
</fileset>
<fileset dir="${thrift.java.dir}/build/deps">
<include name="*.jar"/>
</fileset>
</classpath>
@ -120,19 +124,19 @@
<artifact:remoteRepository id="apache" url="${apache.repo}"/>
<!-- Pom file information -->
<artifact:pom id="pom"
groupId="${thrift.groupid}"
<artifact:pom id="pom"
groupId="${thrift.groupid}"
artifactId="${fb303.artifactid}"
version="${version}"
version="${version}"
url="http://thrift.apache.org"
name="Apache Thrift"
description="Thrift is a software framework for scalable cross-language services development."
packaging="pom"
packaging="jar"
>
<remoteRepository refid="central"/>
<remoteRepository refid="apache"/>
<license name="The Apache Software License, Version 2.0" url="${license}"/>
<scm connection="scm:git:https://git-wip-us.apache.org/repos/asf/thrift.git"
<scm connection="scm:git:https://git-wip-us.apache.org/repos/asf/thrift.git"
developerConnection="scm:git:https://git-wip-us.apache.org/repos/asf/thrift.git"
url="https://git-wip-us.apache.org/repos/asf?p=thrift.git"
/>

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python
#
# Licensed to the Apache Software Foundation (ASF) under one
@ -19,6 +19,7 @@
# under the License.
#
from __future__ import print_function
import sys
import os
from optparse import OptionParser
@ -57,24 +58,20 @@ def service_ctrl(
msg = fb_status_string(status)
if (len(status_details)):
msg += " - %s" % status_details
print msg
if (status == fb_status.ALIVE):
return 2
else:
return 3
print(msg)
return 2 if status == fb_status.ALIVE else 3
except:
print "Failed to get status"
print("Failed to get status")
return 3
# scalar commands
if command in ["version", "alive", "name"]:
try:
result = fb303_wrapper(command, port, trans_factory, prot_factory)
print result
print(result)
return 0
except:
print "failed to get ", command
print("failed to get ", command)
return 3
# counters
@ -82,10 +79,10 @@ def service_ctrl(
try:
counters = fb303_wrapper('counters', port, trans_factory, prot_factory)
for counter in counters:
print "%s: %d" % (counter, counters[counter])
print("%s: %d" % (counter.encode('utf-8'), counters[counter]))
return 0
except:
print "failed to get counters"
print("failed to get counters")
return 3
# Only root should be able to run the following commands
@ -96,19 +93,19 @@ def service_ctrl(
fb303_wrapper(command, port, trans_factory, prot_factory)
return 0
except:
print "failed to tell the service to ", command
print("failed to tell the service to ", command)
return 3
else:
if command in ["stop", "reload"]:
print "root privileges are required to stop or reload the service."
print("root privileges are required to stop or reload the service.")
return 4
print "The following commands are available:"
print("The following commands are available:")
for command in ["counters", "name", "version", "alive", "status"]:
print "\t%s" % command
print "The following commands are available for users with root privileges:"
print("\t%s" % command)
print("The following commands are available for users with root privileges:")
for command in ["stop", "reload"]:
print "\t%s" % command
print("\t%s" % command)
return 0

View file

@ -26,7 +26,7 @@ except:
from distutils.core import setup, Extension, Command
setup(name='thrift_fb303',
version='0.10.0',
version='0.12.0',
description='Python bindings for the Apache Thrift FB303',
author=['Thrift Developers'],
author_email=['dev@thrift.apache.org'],

View file

@ -7,9 +7,9 @@
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
@ -17,8 +17,8 @@
specific language governing permissions and limitations
under the License.
-->
<project
xmlns="http://maven.apache.org/POM/4.0.0"
<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">
@ -27,7 +27,7 @@
<artifactId>thrift-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<name>thrift-maven-plugin</name>
<version>0.10.0</version>
<version>0.12.0</version>
<build>
<plugins>
<plugin>
@ -77,6 +77,12 @@
<artifactId>plexus-utils</artifactId>
<version>3.0.14</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<thrift.root>${basedir}/../..</thrift.root>

View file

@ -117,7 +117,7 @@ abstract class AbstractThriftMojo extends AbstractMojo {
* @parameter default-value="${localRepository}"
* @required
*/
private ArtifactRepository localRepository;
protected ArtifactRepository localRepository;
/**
* Set this to {@code false} to disable hashing of dependent jar paths.
@ -129,7 +129,7 @@ abstract class AbstractThriftMojo extends AbstractMojo {
* @parameter default-value="true"
* @required
*/
private boolean hashDependentPaths;
protected boolean hashDependentPaths;
/**
* @parameter
@ -229,7 +229,7 @@ abstract class AbstractThriftMojo extends AbstractMojo {
checkNotNull(generator, "generator");
final File thriftSourceRoot = getThriftSourceRoot();
checkNotNull(thriftSourceRoot);
checkArgument(!thriftSourceRoot.isFile(), "thriftSourceRoot is a file, not a diretory");
checkArgument(!thriftSourceRoot.isFile(), "thriftSourceRoot is a file, not a directory");
checkNotNull(temporaryThriftFileDirectory, "temporaryThriftFileDirectory");
checkState(!temporaryThriftFileDirectory.isFile(), "temporaryThriftFileDirectory is a file, not a directory");
final File outputDirectory = getOutputDirectory();
@ -268,7 +268,9 @@ abstract class AbstractThriftMojo extends AbstractMojo {
if (temporaryThriftFileDirectory.exists()) {
cleanDirectory(temporaryThriftFileDirectory);
}
Set<File> thriftDirectories = newHashSet();
for (File classpathElementFile : classpathElementFiles) {
// for some reason under IAM, we receive poms as dependent files
// I am excluding .xml rather than including .jar as there may be other extensions in use (sar, har, zip)
@ -283,18 +285,27 @@ abstract class AbstractThriftMojo extends AbstractMojo {
throw new IllegalArgumentException(format(
"%s was not a readable artifact", classpathElementFile));
}
/**
* Copy each .thrift file found in the JAR into a temporary directory, preserving the
* directory path it had relative to its containing JAR. Add the resulting root directory
* (unique for each JAR processed) to the set of thrift include directories to use when
* compiling.
*/
for (JarEntry jarEntry : list(classpathJar.entries())) {
final String jarEntryName = jarEntry.getName();
if (jarEntry.getName().endsWith(THRIFT_FILE_SUFFIX)) {
final String truncatedJarPath = truncatePath(classpathJar.getName());
final File thriftRootDirectory = new File(temporaryThriftFileDirectory, truncatedJarPath);
final File uncompressedCopy =
new File(new File(temporaryThriftFileDirectory,
truncatePath(classpathJar.getName())), jarEntryName);
new File(thriftRootDirectory, jarEntryName);
uncompressedCopy.getParentFile().mkdirs();
copyStreamToFile(new RawInputStreamFacade(classpathJar
.getInputStream(jarEntry)), uncompressedCopy);
thriftDirectories.add(uncompressedCopy.getParentFile());
thriftDirectories.add(thriftRootDirectory);
}
}
} else if (classpathElementFile.isDirectory()) {
File[] thriftFiles = classpathElementFile.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
@ -307,6 +318,7 @@ abstract class AbstractThriftMojo extends AbstractMojo {
}
}
}
return ImmutableSet.copyOf(thriftDirectories);
}
@ -319,15 +331,6 @@ abstract class AbstractThriftMojo extends AbstractMojo {
return ImmutableSet.copyOf(thriftFilesInDirectory);
}
ImmutableSet<File> findThriftFilesInDirectories(Iterable<File> directories) throws IOException {
checkNotNull(directories);
Set<File> thriftFiles = newHashSet();
for (File directory : directories) {
thriftFiles.addAll(findThriftFilesInDirectory(directory));
}
return ImmutableSet.copyOf(thriftFiles);
}
/**
* Truncates the path of jar files so that they are relative to the local repository.
*

View file

@ -23,6 +23,7 @@ import java.io.File;
import java.util.List;
import org.apache.maven.artifact.Artifact;
import com.google.common.collect.ImmutableList;
import org.apache.maven.artifact.repository.ArtifactRepository;
/**
* @phase generate-test-sources
@ -71,4 +72,22 @@ public final class ThriftTestCompileMojo extends AbstractThriftMojo {
protected File getThriftSourceRoot() {
return thriftTestSourceRoot;
}
/**
* Set the local maven ArtifactRepository. Exposed only to allow testing outside of Maven itself.
*
* @param localRepository local ArtifactRepository
*/
public void setLocalMavenRepository(final ArtifactRepository localRepository) {
this.localRepository = localRepository;
}
/**
* Set the option to hash dependent JAR paths. Exposed only to allow testing outside of Maven itself.
*
* @param hashDependentPaths whether or not to hash paths to dependent JARs
*/
public void setHashDependentPaths(final boolean hashDependentPaths) {
this.hashDependentPaths = hashDependentPaths;
}
}

View file

@ -0,0 +1,102 @@
/*
* 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 org.apache.thrift.maven;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import java.io.File;
import java.util.Set;
import static junit.framework.TestCase.assertEquals;
public class TestAbstractThriftMojo {
private ThriftTestCompileMojo mojo;
private File testRootDir;
private ArtifactRepository mavenRepository;
@Before
public void setUp() throws Exception {
final File tmpDir = new File(System.getProperty("java.io.tmpdir"));
testRootDir = new File(tmpDir, "thrift-test");
// the truncatePath method assumes a maven repository, but it only cares about the base dir
mavenRepository = Mockito.mock(ArtifactRepository.class);
Mockito.when(mavenRepository.getBasedir()).thenReturn("/test/maven/repo/basedir");
mojo = new ThriftTestCompileMojo();
mojo.setLocalMavenRepository(mavenRepository);
}
@Test
public void testMakeThriftPathFromJars() throws Throwable {
final File temporaryThriftFileDirectory = testRootDir;
// The SharedIdl.jar file contains the same idl/shared.thrift and idl/tutorial.thrift hierarchy
// used by other tests. It's used here to represent a dependency of the project maven is building,
// one that is contributing .thrift IDL files as well as any other artifacts.
final Iterable<File> classpathElementFiles = Lists.newArrayList(
new File("src/test/resources/dependency-jar-test/SharedIdl.jar")
);
final Set<File> thriftDirectories = mojo.makeThriftPathFromJars(temporaryThriftFileDirectory, classpathElementFiles);
// The results should be a path to a directory named after the JAR itself (assuming no path hashing,
// but see below for a separate test of that) representing the root of a hierarchy containing thrift
// files, suitable for providing to the thrift compiler as an include directory. In this case, that
// means it points to the directory containing the "idl" hierarchy rather than to the idl directory
// itself.
final Set<File> expected = Sets.newHashSet(
new File(testRootDir, "src/test/resources/dependency-jar-test/SharedIdl.jar")
);
assertEquals("makeThriftPathFromJars should return thrift IDL base path from within JAR", expected, thriftDirectories);
}
@Test
public void testTruncatePath() throws Throwable {
// JAR path is unrelated to maven repo, and should be unchanged
assertEquals("/path/to/somejar.jar", mojo.truncatePath("/path/to/somejar.jar"));
// JAR path is within maven repo, and should be made relative to the repo
assertEquals("path/to/somejar.jar", mojo.truncatePath("/test/maven/repo/basedir/path/to/somejar.jar"));
// JAR path contains forward slashes that should be normalized
assertEquals("/path/to/somejar.jar", mojo.truncatePath("\\path\\to\\somejar.jar"));
}
@Test
public void testTruncatePathWithDependentPathHashing() throws Throwable {
mojo.setHashDependentPaths(true);
// hashDependentPaths set to true, the JAR path is immediately hashed (MD5) and converted to a hex string
assertEquals("1c85950987b23493462cf3c261d9510a", mojo.truncatePath("/path/to/somejar.jar"));
assertEquals("39fc2b4c34cb6cb0da38bed5d8b5fc67", mojo.truncatePath("/test/maven/repo/basedir/path/to/somejar.jar"));
assertEquals("25b6924f5b0e19486d0ff88448e999d5", mojo.truncatePath("\\path\\to\\somejar.jar"));
}
}

View file

@ -28,7 +28,7 @@ Name: thrift
License: Apache License v2.0
Group: Development
Summary: RPC and serialization framework
Version: 0.10.0
Version: 0.12.0
Release: 0
URL: http://thrift.apache.org
Packager: Thrift Developers <dev@thrift.apache.org>
@ -234,5 +234,5 @@ umask 007
/sbin/ldconfig > /dev/null 2>&1
%changelog
* Wed Oct 10 2012 Thrift Dev <dev@thrift.apache.org>
* Wed Oct 10 2012 Thrift Dev <dev@thrift.apache.org>
- Thrift 0.9.0 release.

View file

@ -11,7 +11,7 @@ This will download and launch the base box VM under VirtualBox and run the Apach
$ vagrant ssh
[vagrant@thrift ~]$ cd /thrift
[vagrant@thrift thrift]$ compiler/cpp/thrift --version
Thrift version 1.0.0-dev
Thrift version 0.12.0
The provisioning script (inside the Vagrantfile) runs ./bootstrap.sh, ./configure, make and make check, but does not install thrift. To install thrift run "make install".

View file

@ -21,7 +21,7 @@
#include <thrift/transport/TBufferTransports.h>
#include <boost/scoped_ptr.hpp>
using boost::shared_ptr;
using apache::thrift::stdcxx::shared_ptr;
using apache::thrift::transport::TMemoryBuffer;
using apache::thrift::protocol::TProtocol;

View file

@ -28,7 +28,7 @@ namespace apache { namespace thrift { namespace server {
class TZmqServer : public TServer {
public:
TZmqServer(
boost::shared_ptr<TProcessor> processor,
apache::thrift::stdcxx::shared_ptr<TProcessor> processor,
zmq::context_t& ctx, const std::string& endpoint, int type)
: TServer(processor)
, processor_(processor)
@ -56,7 +56,7 @@ class TZmqServer : public TServer {
}
private:
boost::shared_ptr<TProcessor> processor_;
apache::thrift::stdcxx::shared_ptr<TProcessor> processor_;
int zmq_type_;
zmq::socket_t sock_;
};

View file

@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>0.10.0</ProductVersion>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{17C63B90-DFD7-42AC-A7B0-749E6876C0A1}</ProjectGuid>
<OutputType>Exe</OutputType>
@ -25,7 +25,7 @@
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>0.10.0.%2a</ApplicationVersion>
<ApplicationVersion>0.12.0</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
@ -88,4 +88,4 @@
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
</Project>

View file

@ -6,7 +6,7 @@
#include "TZmqClient.h"
#include "Storage.h"
using boost::shared_ptr;
using apache::thrift::stdcxx::shared_ptr;
using apache::thrift::transport::TZmqClient;
using apache::thrift::protocol::TBinaryProtocol;
@ -17,7 +17,7 @@ int main(int argc, char** argv) {
if (argc > 1) {
incr = atoi(argv[1]);
if (incr) {
socktype = ZMQ_DOWNSTREAM;
socktype = ZMQ_PUSH;
endpoint = "tcp://127.0.0.1:9091";
}
}

View file

@ -15,7 +15,7 @@ def main(args):
if len(args) > 1:
incr = int(args[1])
if incr:
socktype = zmq.DOWNSTREAM
socktype = zmq.PUSH
endpoint = "tcp://127.0.0.1:9091"
ctx = zmq.Context()
@ -29,7 +29,7 @@ def main(args):
time.sleep(0.05)
else:
value = client.get()
print value
print(value)
if __name__ == "__main__":

View file

@ -2,7 +2,7 @@
#include "TZmqServer.h"
#include "Storage.h"
using boost::shared_ptr;
using apache::thrift::stdcxx::shared_ptr;
using apache::thrift::TProcessor;
using apache::thrift::server::TZmqServer;
using apache::thrift::server::TZmqMultiServer;

View file

@ -6,7 +6,7 @@
#include "TZmqClient.h"
#include "Storage.h"
using boost::shared_ptr;
using apache::thrift::stdcxx::shared_ptr;
using apache::thrift::transport::TZmqClient;
using apache::thrift::protocol::TBinaryProtocol;

View file

@ -2,7 +2,7 @@
#include "TZmqServer.h"
#include "Storage.h"
using boost::shared_ptr;
using apache::thrift::stdcxx::shared_ptr;
using apache::thrift::TProcessor;
using apache::thrift::server::TZmqServer;
using apache::thrift::server::TZmqMultiServer;
@ -33,7 +33,7 @@ int main(int argc, char *argv[]) {
zmq::context_t ctx(1);
TZmqServer reqrep_server(processor, ctx, "tcp://0.0.0.0:9090", ZMQ_REP);
TZmqServer oneway_server(processor, ctx, "tcp://0.0.0.0:9091", ZMQ_UPSTREAM);
TZmqServer oneway_server(processor, ctx, "tcp://0.0.0.0:9091", ZMQ_PULL);
TZmqMultiServer multiserver;
multiserver.servers().push_back(&reqrep_server);
multiserver.servers().push_back(&oneway_server);

View file

@ -22,7 +22,7 @@ def main():
ctx = zmq.Context()
reqrep_server = TZmqServer.TZmqServer(processor, ctx, "tcp://0.0.0.0:9090", zmq.REP)
oneway_server = TZmqServer.TZmqServer(processor, ctx, "tcp://0.0.0.0:9091", zmq.UPSTREAM)
oneway_server = TZmqServer.TZmqServer(processor, ctx, "tcp://0.0.0.0:9091", zmq.PULL)
multiserver = TZmqServer.TZmqMultiServer()
multiserver.servers.append(reqrep_server)
multiserver.servers.append(oneway_server)