Skip to content

Commit

Permalink
renaming/changing FunctionConfig (apache#1552)
Browse files Browse the repository at this point in the history
* renaming/changing FunctionConfig

* adding missing license header

* moving FunctionConfig to different module
  • Loading branch information
jerrypeng authored and sijie committed Apr 12, 2018
1 parent aff6c04 commit 3fbb4c9
Show file tree
Hide file tree
Showing 49 changed files with 1,083 additions and 1,002 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public Response registerFunction(final @PathParam("tenant") String tenant,
final @PathParam("functionName") String functionName,
final @FormDataParam("data") InputStream uploadedInputStream,
final @FormDataParam("data") FormDataContentDisposition fileDetail,
final @FormDataParam("functionConfig") String functionConfigJson) {
final @FormDataParam("functionDetails") String functionDetailsJson) {

return functions.registerFunction(
tenant, namespace, functionName, uploadedInputStream, fileDetail, functionConfigJson);
tenant, namespace, functionName, uploadedInputStream, fileDetail, functionDetailsJson);

}

Expand All @@ -72,10 +72,10 @@ public Response updateFunction(final @PathParam("tenant") String tenant,
final @PathParam("functionName") String functionName,
final @FormDataParam("data") InputStream uploadedInputStream,
final @FormDataParam("data") FormDataContentDisposition fileDetail,
final @FormDataParam("functionConfig") String functionConfigJson) {
final @FormDataParam("functionDetails") String functionDetailsJson) {

return functions.updateFunction(
tenant, namespace, functionName, uploadedInputStream, fileDetail, functionConfigJson);
tenant, namespace, functionName, uploadedInputStream, fileDetail, functionDetailsJson);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.apache.pulsar.client.admin.PulsarAdminException.NotAuthorizedException;
import org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException;
import org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException;
import org.apache.pulsar.functions.shaded.proto.Function.FunctionConfig;
import org.apache.pulsar.functions.shaded.proto.Function.FunctionDetails;
import org.apache.pulsar.functions.shaded.proto.InstanceCommunication.FunctionStatusList;

import java.util.List;
Expand Down Expand Up @@ -73,24 +73,24 @@ public interface Functions {
* @throws PulsarAdminException
* Unexpected error
*/
FunctionConfig getFunction(String tenant, String namespace, String function) throws PulsarAdminException;
FunctionDetails getFunction(String tenant, String namespace, String function) throws PulsarAdminException;

/**
* Create a new function.
*
* @param functionConfig
* @param functionDetails
* the function configuration object
*
* @throws PulsarAdminException
* Unexpected error
*/
void createFunction(FunctionConfig functionConfig, String fileName) throws PulsarAdminException;
void createFunction(FunctionDetails functionDetails, String fileName) throws PulsarAdminException;

/**
* Update the configuration for a function.
* <p>
*
* @param functionConfig
* @param functionDetails
* the function configuration object
*
* @throws NotAuthorizedException
Expand All @@ -100,7 +100,7 @@ public interface Functions {
* @throws PulsarAdminException
* Unexpected error
*/
void updateFunction(FunctionConfig functionConfig, String fileName) throws PulsarAdminException;
void updateFunction(FunctionDetails functionDetails, String fileName) throws PulsarAdminException;

/**
* Delete an existing function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.client.api.Authentication;
import org.apache.pulsar.common.policies.data.*;
import org.apache.pulsar.functions.shaded.proto.Function.FunctionConfig;
import org.apache.pulsar.functions.shaded.proto.Function.FunctionDetails;
import org.apache.pulsar.functions.shaded.proto.InstanceCommunication.FunctionStatusList;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
Expand Down Expand Up @@ -68,16 +68,16 @@ public List<String> getFunctions(String tenant, String namespace) throws PulsarA
}

@Override
public FunctionConfig getFunction(String tenant, String namespace, String function) throws PulsarAdminException {
public FunctionDetails getFunction(String tenant, String namespace, String function) throws PulsarAdminException {
try {
Response response = request(functions.path(tenant).path(namespace).path(function)).get();
if (!response.getStatusInfo().equals(Response.Status.OK)) {
throw new ClientErrorException(response);
}
String jsonResponse = response.readEntity(String.class);
FunctionConfig.Builder functionConfigBuilder = FunctionConfig.newBuilder();
mergeJson(jsonResponse, functionConfigBuilder);
return functionConfigBuilder.build();
FunctionDetails.Builder functionDetailsBuilder = FunctionDetails.newBuilder();
mergeJson(jsonResponse, functionDetailsBuilder);
return functionDetailsBuilder.build();
} catch (Exception e) {
throw getApiException(e);
}
Expand All @@ -101,16 +101,16 @@ public FunctionStatusList getFunctionStatus(
}

@Override
public void createFunction(FunctionConfig functionConfig, String fileName) throws PulsarAdminException {
public void createFunction(FunctionDetails functionDetails, String fileName) throws PulsarAdminException {
try {
final FormDataMultiPart mp = new FormDataMultiPart();

mp.bodyPart(new FileDataBodyPart("data", new File(fileName), MediaType.APPLICATION_OCTET_STREAM_TYPE));

mp.bodyPart(new FormDataBodyPart("functionConfig",
printJson(functionConfig),
mp.bodyPart(new FormDataBodyPart("functionDetails",
printJson(functionDetails),
MediaType.APPLICATION_JSON_TYPE));
request(functions.path(functionConfig.getTenant()).path(functionConfig.getNamespace()).path(functionConfig.getName()))
request(functions.path(functionDetails.getTenant()).path(functionDetails.getNamespace()).path(functionDetails.getName()))
.post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA), ErrorData.class);
} catch (Exception e) {
throw getApiException(e);
Expand All @@ -128,16 +128,16 @@ public void deleteFunction(String cluster, String namespace, String function) th
}

@Override
public void updateFunction(FunctionConfig functionConfig, String fileName) throws PulsarAdminException {
public void updateFunction(FunctionDetails functionDetails, String fileName) throws PulsarAdminException {
try {
final FormDataMultiPart mp = new FormDataMultiPart();
if (fileName != null) {
mp.bodyPart(new FileDataBodyPart("data", new File(fileName), MediaType.APPLICATION_OCTET_STREAM_TYPE));
}
mp.bodyPart(new FormDataBodyPart("functionConfig",
printJson(functionConfig),
mp.bodyPart(new FormDataBodyPart("functionDetails",
printJson(functionDetails),
MediaType.APPLICATION_JSON_TYPE));
request(functions.path(functionConfig.getTenant()).path(functionConfig.getNamespace()).path(functionConfig.getName()))
request(functions.path(functionDetails.getTenant()).path(functionDetails.getNamespace()).path(functionDetails.getName()))
.put(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA), ErrorData.class);
} catch (Exception e) {
throw getApiException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import org.apache.pulsar.functions.api.Context;
import org.apache.pulsar.functions.api.Function;
import org.apache.pulsar.functions.api.utils.DefaultSerDe;
import org.apache.pulsar.functions.shaded.proto.Function.FunctionConfig;
import org.apache.pulsar.functions.shaded.proto.Function.FunctionDetails;
import org.apache.pulsar.functions.shaded.io.netty.buffer.ByteBuf;
import org.apache.pulsar.functions.shaded.io.netty.buffer.ByteBufUtil;
import org.apache.pulsar.functions.utils.Reflections;
Expand Down Expand Up @@ -188,7 +188,7 @@ public void testCreateFunction() throws Exception {
assertEquals(inputTopicName, creater.getInputs());
assertEquals(outputTopicName, creater.getOutput());

verify(functions, times(1)).createFunction(any(FunctionConfig.class), anyString());
verify(functions, times(1)).createFunction(any(FunctionDetails.class), anyString());

}

Expand All @@ -209,7 +209,7 @@ public void testCreateWithoutTenant() throws Exception {

CreateFunction creater = cmd.getCreater();
assertEquals("tenant", creater.getFunctionConfig().getTenant());
verify(functions, times(1)).createFunction(any(FunctionConfig.class), anyString());
verify(functions, times(1)).createFunction(any(FunctionDetails.class), anyString());
}

@Test
Expand All @@ -229,7 +229,7 @@ public void testCreateWithoutNamespace() throws Exception {
CreateFunction creater = cmd.getCreater();
assertEquals("tenant", creater.getFunctionConfig().getTenant());
assertEquals("namespace", creater.getFunctionConfig().getNamespace());
verify(functions, times(1)).createFunction(any(FunctionConfig.class), anyString());
verify(functions, times(1)).createFunction(any(FunctionDetails.class), anyString());
}

@Test
Expand All @@ -254,7 +254,7 @@ public void testCreateUsingFullyQualifiedFunctionName() throws Exception {
assertEquals(tenant, creater.getFunctionConfig().getTenant());
assertEquals(namespace, creater.getFunctionConfig().getNamespace());
assertEquals(functionName, creater.getFunctionConfig().getName());
verify(functions, times(1)).createFunction(any(FunctionConfig.class), anyString());
verify(functions, times(1)).createFunction(any(FunctionDetails.class), anyString());
}

@Test
Expand All @@ -273,7 +273,7 @@ public void testCreateWithoutFunctionName() throws Exception {

CreateFunction creater = cmd.getCreater();
assertEquals("CmdFunctionsTest$DummyFunction", creater.getFunctionConfig().getName());
verify(functions, times(1)).createFunction(any(FunctionConfig.class), anyString());
verify(functions, times(1)).createFunction(any(FunctionDetails.class), anyString());
}

@Test
Expand All @@ -290,7 +290,7 @@ public void testCreateWithoutOutputTopic() throws Exception {

CreateFunction creater = cmd.getCreater();
assertEquals(inputTopicName + "-" + "CmdFunctionsTest$DummyFunction" + "-output", creater.getFunctionConfig().getOutput());
verify(functions, times(1)).createFunction(any(FunctionConfig.class), anyString());
verify(functions, times(1)).createFunction(any(FunctionDetails.class), anyString());
}

@Test
Expand Down Expand Up @@ -359,7 +359,7 @@ public void testUpdateFunction() throws Exception {
assertEquals(inputTopicName, updater.getInputs());
assertEquals(outputTopicName, updater.getOutput());

verify(functions, times(1)).updateFunction(any(FunctionConfig.class), anyString());
verify(functions, times(1)).updateFunction(any(FunctionDetails.class), anyString());
}

@Test
Expand Down
Loading

0 comments on commit 3fbb4c9

Please sign in to comment.