Skip to content

Commit

Permalink
[ISSUE#662]capitalizing the first letter in comments and removing the…
Browse files Browse the repository at this point in the history
… unless comments for acl and msg trace feature codes. (apache#669)

* [ISSUE#662]capitalizing the first letter in comments and removing the  unless comments for acl and msg trace feature codes.

* [ISSUE#662]polish the acl feature codes.
  • Loading branch information
zongtanghu authored and dongeforever committed Jan 7, 2019
1 parent ea8d517 commit 691b712
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public interface AccessValidator {
* Parse to get the AccessResource(user, resource, needed permission)
*
* @param request
* @return
* @param remoteAddr
* @return Plain access resource result,include access key,signature and some other access attributes.
*/
AccessResource parse(RemotingCommand request, String remoteAddr);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public void doBeforeRequest(String remoteAddr, RemotingCommand request) {
String signature = AclUtils.calSignature(total, sessionCredentials.getSecretKey());
request.addExtField(SIGNATURE, signature);
request.addExtField(ACCESS_KEY, sessionCredentials.getAccessKey());


// The SecurityToken value is unneccessary,user can choose this one.
if (sessionCredentials.getSecurityToken() != null) {
request.addExtField(SECURITY_TOKEN, sessionCredentials.getSecurityToken());
}
Expand All @@ -57,14 +58,14 @@ public void doAfterResponse(String remoteAddr, RemotingCommand request, Remoting

protected SortedMap<String, String> parseRequestContent(RemotingCommand request, String ak, String securityToken) {
CommandCustomHeader header = request.readCustomHeader();
// sort property
// Sort property
SortedMap<String, String> map = new TreeMap<String, String>();
map.put(ACCESS_KEY, ak);
if (securityToken != null) {
map.put(SECURITY_TOKEN, securityToken);
}
try {
// add header properties
// Add header properties
if (null != header) {
Field[] fields = fieldCache.get(header.getClass());
if (null == fields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.apache.rocketmq.acl.common;

public class AclException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = -7256002576788700354L;

private String status;
private int code;
Expand All @@ -34,12 +34,6 @@ public AclException(String status, int code, String message) {
this.code = code;
}

public AclException(String status, int code, Throwable throwable) {
super(throwable);
this.status = status;
this.code = code;
}

public AclException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public class Permission {
public static final Set<Integer> ADMIN_CODE = new HashSet<Integer>();

static {
// UPDATE_AND_CREATE_TOPIC
// UPDATE_AND_CREATE_TOPIC
ADMIN_CODE.add(RequestCode.UPDATE_AND_CREATE_TOPIC);
// UPDATE_BROKER_CONFIG
// UPDATE_BROKER_CONFIG
ADMIN_CODE.add(RequestCode.UPDATE_BROKER_CONFIG);
// DELETE_TOPIC_IN_BROKER
// DELETE_TOPIC_IN_BROKER
ADMIN_CODE.add(RequestCode.DELETE_TOPIC_IN_BROKER);
// UPDATE_AND_CREATE_SUBSCRIPTIONGROUP
ADMIN_CODE.add(RequestCode.UPDATE_AND_CREATE_SUBSCRIPTIONGROUP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public class PlainAccessResource implements AccessResource {

//identify the user
// Identify the user
private String accessKey;

private String secretKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public AccessResource parse(RemotingCommand request, String remoteAddr) {
} catch (Throwable t) {
throw new AclException(t.getMessage(), t);
}
// content
// Content
SortedMap<String, String> map = new TreeMap<String, String>();
for (Map.Entry<String, String> entry : request.getExtFields().entrySet()) {
if (!SessionCredentials.SIGNATURE.equals(entry.getKey())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void checkPerm(PlainAccessResource needCheckedAccess, PlainAccessResource ownedA
Map<String, Byte> ownedPermMap = ownedAccess.getResourcePermMap();

if (needCheckedPermMap == null) {
//if the needCheckedPermMap is null,then return
// If the needCheckedPermMap is null,then return
return;
}

Expand All @@ -129,7 +129,7 @@ void checkPerm(PlainAccessResource needCheckedAccess, PlainAccessResource ownedA
boolean isGroup = PlainAccessResource.isRetryTopic(resource);

if (!ownedPermMap.containsKey(resource)) {
//Check the default perm
// Check the default perm
byte ownedPerm = isGroup ? needCheckedAccess.getDefaultGroupPerm() :
needCheckedAccess.getDefaultTopicPerm();
if (!Permission.checkPermission(neededPerm, ownedPerm)) {
Expand Down Expand Up @@ -178,7 +178,7 @@ public PlainAccessResource buildPlainAccessResource(PlainAccessConfig plainAcces

public void validate(PlainAccessResource plainAccessResource) {

//Step 1, check the global white remote addr
// Check the global white remote addr
for (RemoteAddressStrategy remoteAddressStrategy : globalWhiteRemoteAddressStrategy) {
if (remoteAddressStrategy.match(plainAccessResource)) {
return;
Expand All @@ -193,18 +193,18 @@ public void validate(PlainAccessResource plainAccessResource) {
throw new AclException(String.format("No acl config for %s", plainAccessResource.getAccessKey()));
}

//Step 2, check the white addr for accesskey
// Check the white addr for accesskey
PlainAccessResource ownedAccess = plainAccessResourceMap.get(plainAccessResource.getAccessKey());
if (ownedAccess.getRemoteAddressStrategy().match(plainAccessResource)) {
return;
}

//Step 3, check the signature
// Check the signature
String signature = AclUtils.calSignature(plainAccessResource.getContent(), ownedAccess.getSecretKey());
if (!signature.equals(plainAccessResource.getSignature())) {
throw new AclException(String.format("Check signature failed for accessKey=%s", plainAccessResource.getAccessKey()));
}
//Step 4, check perm of each resource
// Check perm of each resource

checkPerm(plainAccessResource, ownedAccess);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

public interface RemoteAddressStrategy {

public boolean match(PlainAccessResource plainAccessResource);
boolean match(PlainAccessResource plainAccessResource);
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public DefaultMQPushConsumer() {
*
* @param consumerGroup Consume queue.
* @param rpcHook RPC hook to execute before each remoting command.
* @param allocateMessageQueueStrategy message queue allocating algorithm.
* @param allocateMessageQueueStrategy Message queue allocating algorithm.
*/
public DefaultMQPushConsumer(final String consumerGroup, RPCHook rpcHook,
AllocateMessageQueueStrategy allocateMessageQueueStrategy) {
Expand All @@ -280,13 +280,13 @@ public DefaultMQPushConsumer(final String consumerGroup, RPCHook rpcHook,
}

/**
* Constructor specifying consumer group, RPC hook and message queue allocating algorithm.
* Constructor specifying consumer group, RPC hook, message queue allocating algorithm, enabled msg trace flag and customized trace topic name.
*
* @param consumerGroup Consume queue.
* @param rpcHook RPC hook to execute before each remoting command.
* @param allocateMessageQueueStrategy message queue allocating algorithm.
* @param enableMsgTrace switch flag instance for message trace.
* @param customizedTraceTopic the name value of message trace topic.If you don't config,you can use the default trace topic name.
* @param enableMsgTrace Switch flag instance for message trace.
* @param customizedTraceTopic The name value of message trace topic.If you don't config,you can use the default trace topic name.
*/
public DefaultMQPushConsumer(final String consumerGroup, RPCHook rpcHook,
AllocateMessageQueueStrategy allocateMessageQueueStrategy, boolean enableMsgTrace, final String customizedTraceTopic) {
Expand Down Expand Up @@ -317,21 +317,21 @@ public DefaultMQPushConsumer(RPCHook rpcHook) {


/**
* Constructor specifying consumer group.
* Constructor specifying consumer group and enabled msg trace flag.
*
* @param consumerGroup Consumer group.
* @param enableMsgTrace switch flag instance for message trace.
* @param enableMsgTrace Switch flag instance for message trace.
*/
public DefaultMQPushConsumer(final String consumerGroup, boolean enableMsgTrace) {
this(consumerGroup, null, new AllocateMessageQueueAveragely(), enableMsgTrace, null);
}

/**
* Constructor specifying consumer group.
* Constructor specifying consumer group, enabled msg trace flag and customized trace topic name.
*
* @param consumerGroup Consumer group.
* @param enableMsgTrace switch flag instance for message trace.
* @param customizedTraceTopic the name value of message trace topic.If you don't config,you can use the default trace topic name.
* @param enableMsgTrace Switch flag instance for message trace.
* @param customizedTraceTopic The name value of message trace topic.If you don't config,you can use the default trace topic name.
*/
public DefaultMQPushConsumer(final String consumerGroup, boolean enableMsgTrace, final String customizedTraceTopic) {
this(consumerGroup, null, new AllocateMessageQueueAveragely(), enableMsgTrace, customizedTraceTopic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ public DefaultMQProducer(final String producerGroup, RPCHook rpcHook) {
}

/**
* Constructor specifying both producer group and RPC hook.
* Constructor specifying producer group, RPC hook, enabled msgTrace flag and customized trace topic name.
*
* @param producerGroup Producer group, see the name-sake field.
* @param rpcHook RPC hook to execute per each remoting command execution.
* @param enableMsgTrace switch flag instance for message trace.
* @param customizedTraceTopic the name value of message trace topic.If you don't config,you can use the default trace topic name.
* @param enableMsgTrace Switch flag instance for message trace.
* @param customizedTraceTopic The name value of message trace topic.If you don't config,you can use the default trace topic name.
*/
public DefaultMQProducer(final String producerGroup, RPCHook rpcHook, boolean enableMsgTrace,final String customizedTraceTopic) {
this.producerGroup = producerGroup;
Expand Down Expand Up @@ -184,22 +184,22 @@ public DefaultMQProducer(final String producerGroup) {
}

/**
* Constructor specifying producer group.
* Constructor specifying producer group and enabled msg trace flag.
*
* @param producerGroup Producer group, see the name-sake field.
* @param enableMsgTrace switch flag instance for message trace.
* @param enableMsgTrace Switch flag instance for message trace.
*/
public DefaultMQProducer(final String producerGroup, boolean enableMsgTrace) {
this(producerGroup, null, enableMsgTrace, null);
}


/**
* Constructor specifying producer group.
* Constructor specifying producer group, enabled msgTrace flag and customized trace topic name.
*
* @param producerGroup Producer group, see the name-sake field.
* @param enableMsgTrace switch flag instance for message trace.
* @param customizedTraceTopic the name value of message trace topic.If you don't config,you can use the default trace topic name.
* @param enableMsgTrace Switch flag instance for message trace.
* @param customizedTraceTopic The name value of message trace topic.If you don't config,you can use the default trace topic name.
*/
public DefaultMQProducer(final String producerGroup, boolean enableMsgTrace, final String customizedTraceTopic) {
this(producerGroup, null, enableMsgTrace, customizedTraceTopic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class AsyncTraceDispatcher implements TraceDispatcher {
private final int maxMsgSize;
private final DefaultMQProducer traceProducer;
private final ThreadPoolExecutor traceExecuter;
// the last discard number of log
// The last discard number of log
private AtomicLong discardCount;
private Thread worker;
private ArrayBlockingQueue<TraceContext> traceContextQueue;
Expand Down Expand Up @@ -143,7 +143,7 @@ private DefaultMQProducer getAndCreateTraceProducer(RPCHook rpcHook) {
traceProducerInstance.setSendMsgTimeout(5000);
traceProducerInstance.setInstanceName(TRACE_INSTANCE_NAME);
traceProducerInstance.setVipChannelEnabled(false);
//the max size of message is 128K
// The max size of message is 128K
traceProducerInstance.setMaxMessageSize(maxMsgSize - 10 * 1000);
}
return traceProducerInstance;
Expand All @@ -160,7 +160,7 @@ public boolean append(final Object ctx) {

@Override
public void flush() throws IOException {
// the maximum waiting time for refresh,avoid being written all the time, resulting in failure to return.
// The maximum waiting time for refresh,avoid being written all the time, resulting in failure to return.
long end = System.currentTimeMillis() + 500;
while (traceContextQueue.size() > 0 || appenderQueue.size() > 0 && System.currentTimeMillis() <= end) {
try {
Expand Down Expand Up @@ -263,9 +263,9 @@ public void sendTraceData(List<TraceContext> contextList) {
if (context.getTraceBeans().isEmpty()) {
continue;
}
//1.topic value corresponding to original message entity content
// Topic value corresponding to original message entity content
String topic = context.getTraceBeans().get(0).getTopic();
//2.use original message entity's topic as key
// Use original message entity's topic as key
String key = topic;
List<TraceTransferBean> transBeanList = transBeanMap.get(key);
if (transBeanList == null) {
Expand All @@ -281,26 +281,26 @@ public void sendTraceData(List<TraceContext> contextList) {
}

/**
* batch sending data actually
* Batch sending data actually
*/
private void flushData(List<TraceTransferBean> transBeanList) {
if (transBeanList.size() == 0) {
return;
}
// temporary buffer
// Temporary buffer
StringBuilder buffer = new StringBuilder(1024);
int count = 0;
Set<String> keySet = new HashSet<String>();

for (TraceTransferBean bean : transBeanList) {
// keyset of message trace includes msgId of or original message
// Keyset of message trace includes msgId of or original message
keySet.addAll(bean.getTransKey());
buffer.append(bean.getTransData());
count++;
// Ensure that the size of the package should not exceed the upper limit.
if (buffer.length() >= traceProducer.getMaxMessageSize()) {
sendTraceDataByMQ(keySet, buffer.toString());
// clear temporary buffer after finishing
// Clear temporary buffer after finishing
buffer.delete(0, buffer.length());
keySet.clear();
count = 0;
Expand All @@ -313,7 +313,7 @@ private void flushData(List<TraceTransferBean> transBeanList) {
}

/**
* send message trace data
* Send message trace data
*
* @param keySet the keyset in this batch(including msgId in original message not offsetMsgId)
* @param data the message trace data in this batch
Expand All @@ -322,7 +322,7 @@ private void sendTraceDataByMQ(Set<String> keySet, final String data) {
String topic = traceTopicName;
final Message message = new Message(topic, data.getBytes());

//keyset of message trace includes msgId of or original message
// Keyset of message trace includes msgId of or original message
message.setKeys(keySet);
try {
Set<String> traceBrokerSet = tryGetMessageQueueBrokerSet(traceProducer.getDefaultMQProducerImpl(), topic);
Expand All @@ -337,7 +337,7 @@ public void onException(Throwable e) {
}
};
if (traceBrokerSet.isEmpty()) {
//no cross set
// No cross set
traceProducer.send(message, callback, 5000);
} else {
traceProducer.send(message, new MessageQueueSelector() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import java.util.List;

/**
* encode/decode for Trace Data
* Encode/decode for Trace Data
*/
public class TraceDataEncoder {

/**
* resolving traceContext list From trace data String
* Resolving traceContext list From trace data String
*
* @param traceData
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ public interface TraceDispatcher {
void start(String nameSrvAddr) throws MQClientException;

/**
* append the transfering data
* Append the transfering data
* @param ctx data infomation
* @return
*/
boolean append(Object ctx);

/**
* write flush action
* Write flush action
*
* @throws IOException
*/
void flush() throws IOException;

/**
* close the trace Hook
* Close the trace Hook
*/
void shutdown();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Set;

/**
* trace transfering bean
* Trace transfering bean
*/
public class TraceTransferBean {
private String transData;
Expand Down
Loading

0 comments on commit 691b712

Please sign in to comment.