Alter client quotas using kafka-python - apache-kafka

I'm using kafka-python library to manage my kafka cluster. I want to add the quotas features (alter/describe), these features are not yet implented in kafka-python library but they are available in kafka protocol doc here.
AlterClientQuotas API (Key: 49):
Requests:
AlterClientQuotas Request (Version: 0) => [entries] validate_only
entries => [entity] [ops]
entity => entity_type entity_name
entity_type => STRING
entity_name => NULLABLE_STRING
ops => key value remove
key => STRING
value => FLOAT64
remove => BOOLEAN
validate_only => BOOLEAN
Responses:
AlterClientQuotas Response (Version: 0) => throttle_time_ms [entries]
throttle_time_ms => INT32
entries => error_code error_message [entity]
error_code => INT16
error_message => NULLABLE_STRING
entity => entity_type entity_name
entity_type => STRING
entity_name => NULLABLE_STRING
To implement these features I'm adding the following code
kafka/protocol/admin.py
from kafka.protocol.api import Request, Response
class AlterClientQuotasResponse_v0(Response):
API_KEY = 49
API_VERSION = 0
SCHEMA = Schema(
("throttle_time_ms", Int32),
(
"entries",
Array(
("error_code", Int16),
("error_message", String),
("match", CompactString("utf-8")),
(
"entity",
Array(
("entity_type", String("utf-8")),
("entity_name", String("utf-8")),
),
),
),
),
)
class AlterClientQuotasResponse_v1(Response):
API_KEY = 49
API_VERSION = 0
SCHEMA = Schema(
("throttle_time_ms", Int32),
(
"entries",
Array(
("error_code", Int16),
("error_message", String),
("match", CompactString("utf-8")),
(
"entity",
Array(
("entity_type", String("utf-8")),
("entity_name", String("utf-8")),
),
),
("tags", TaggedFields),
),
),
)
class AlterClientQuotasRequest_v0(Request):
API_KEY = 49
API_VERSION = 0
RESPONSE_TYPE = AlterClientQuotasResponse_v0
SCHEMA = Schema(
(
"entries", Array(
("entity_type", String("utf-8")),
("entity_name", String("utf-8")),
)
),
(
"ops", Array(
("key", String("utf-8")),
("value", Float64),
("remove", Boolean),
)
),
("validate_only", Boolean)
)
class AlterClientQuotasRequest_v1(Request):
API_KEY = 49
API_VERSION = 0
RESPONSE_TYPE = AlterClientQuotasResponse_v1
SCHEMA = Schema(
(
"entries", Array(
("entity_type", String("utf-8")),
("entity_name", String("utf-8")),
)
),
(
"ops", Array(
("key", String("utf-8")),
("value", Float64),
("remove", Boolean),
)
),
("validate_only", Boolean),
("tags", TaggedFields),
)
AlterClientQuotasResponse = [
AlterClientQuotasResponse_v0,
AlterClientQuotasResponse_v1
]
AlterClientQuotasRequest = [
AlterClientQuotasRequest_v0,
AlterClientQuotasRequest_v1
]
kafka/admin/client.py
request = AlterClientQuotasRequest[0](
entries=[("user", "<...>.producer"),],
ops=[("producer_byte_rate", 1024, False),],
validate_only=True,
#tags={}
)
print("--> Quota Request :", request)
future = self._send_request_to_node(self._client.least_loaded_node(), request)
self._wait_for_futures([future])
print("-->>> FUTURE Value", future.value)
Running the code below gets the follwing errors :
client output
File /<...>/py310/lib/python3.10/site-packages/kafka/admin/client.py:1342, in KafkaAdminClient._wait_for_futures(self, futures)
1339 self._client.poll(future=future)
1341 if future.failed():
-> 1342 raise future.exception
KafkaConnectionError: KafkaConnectionError: socket disconnected
server output
Feb 03 11:24:25 broker-05: org.apache.kafka.common.errors.InvalidRequestException: Error getting request for apiKey: ALTER_CLIENT_QUOTAS, apiVersion: 0, connectionId: , listenerName: ListenerName(SECURED), principal: User:
Feb 03 11:24:25 broker-05 Caused by: java.lang.RuntimeException: Tried to allocate a collection of size 292211, but there are only 71 bytes remaining.
Feb 03 11:24:25 broker-05 at org.apache.kafka.common.message.AlterClientQuotasRequestData$EntryData.read(AlterClientQuotasRequestData.java:347)
Feb 03 11:24:25 broker-05 at org.apache.kafka.common.message.AlterClientQuotasRequestData$EntryData.(AlterClientQuotasRequestData.java:300)
Feb 03 11:24:25 broker-05 at org.apache.kafka.common.message.AlterClientQuotasRequestData.read(AlterClientQuotasRequestData.java:125)
Feb 03 11:24:25 broker-05 at org.apache.kafka.common.message.AlterClientQuotasRequestData.(AlterClientQuotasRequestData.java:73)
Feb 03 11:24:25 broker-05 at org.apache.kafka.common.requests.AlterClientQuotasRequest.parse(AlterClientQuotasRequest.java:142)
Feb 03 11:24:25 broker-05 at org.apache.kafka.common.requests.AbstractRequest.doParseRequest(AbstractRequest.java:269)
Feb 03 11:24:25 broker-05 at org.apache.kafka.common.requests.AbstractRequest.parseRequest(AbstractRequest.java:165)
Feb 03 11:24:25 broker-05 at org.apache.kafka.common.requests.RequestContext.parseRequest(RequestContext.java:95)
Feb 03 11:24:25 broker-05 at kafka.network.RequestChannel$Request.(RequestChannel.scala:101)
Feb 03 11:24:25 broker-05 at kafka.network.Processor.$anonfun$processCompletedReceives$1(SocketServer.scala:1096)
Feb 03 11:24:25 broker-05 at java.base/java.util.LinkedHashMap$LinkedValues.forEach(LinkedHashMap.java:608)
Feb 03 11:24:25 broker-05 at kafka.network.Processor.processCompletedReceives(SocketServer.scala:1074)
Feb 03 11:24:25 broker-05 at kafka.network.Processor.run(SocketServer.scala:960)
Feb 03 11:24:25 broker-05 at java.base/java.lang.Thread.run(Thread.java:829)
Has anyone been able to implement this ?
help please ?
Thank you !

Related

SMTP Error (454): Failed to add recipient Relay access denied roundcube

I setup a mail server on VPS and I installed roundcube to manage webmail. when i send e-mail in intern it work's but when i try to send an e-mail to another mail server (gmail) i get this error :
SMTP Error (454): Failed to add recipient "user#gmail.com" (4.7.1 : Relay access denied).
but when i send the same e-mail with thunderbird it works so here what i found at logs:
with roundcube:
Dec 4 18:44:09 vpsxxxxxx postfix/smtpd[3013]: connect from xxx.xxx.xxx.xxx
Dec 4 18:44:09 vpsxxxxxx postfix/smtpd[3013]: warning: connect to Milter service inet:127.0.0.1:8891: Connection refused
Dec 4 18:44:09 vpsxxxxxx postfix/smtpd[3013]: NOQUEUE: reject: RCPT from xxx.xxx.xxx.xxx: 454 4.7.1 <user#gmail.com>: Relay access denied; from=<user#domain.com> to=<user#gmail.com> proto=ESMTP helo=<mail.domain.com>
Dec 4 18:44:09 vpsxxxxxx postfix/smtpd[3013]: disconnect from xxx.xxx.xxx.xxx ehlo=1 mail=1 rcpt=0/1 rset=1 quit=1 commands=4/5
with thunderbird :
Dec 4 18:44:55 vpsxxxxxx postfix/smtpd[3016]: connect from unknown[xxx.xxx.xxx.xxx]
Dec 4 18:44:55 vpsxxxxxx postfix/smtpd[3016]: warning: connect to Milter service inet:127.0.0.1:8891: Connection refused
Dec 4 18:44:58 vpsxxxxxx postfix/smtpd[3016]: 64DCD5EEC4: client=unknown[xxx.xxx.xxx.xxx], sasl_method=PLAIN, sasl_username=user#domain.com
Dec 4 18:44:58 vpsxxxxxx postfix/cleanup[3019]: 64DCD5EEC4: message-id=<9bf8a7ca-9d6a-847c-5350-0f5c4350951f#domain.com>
Dec 4 18:44:58 vpsxxxxxx postfix/qmgr[2865]: 64DCD5EEC4: from=<user#domain.com>, size=1810, nrcpt=1 (queue active)
Dec 4 18:44:58 vpsxxxxxx postfix/smtpd[3016]: disconnect from unknown[xxx.xxx.xxx.xxx] ehlo=2 starttls=1 auth=1 mail=1 rcpt=1 data=1 quit=1 commands=8
Dec 4 18:44:59 vpsxxxxxx postfix/smtp[3020]: connect to gmail-smtp-in.l.google.com[2a00:1450:400c:c07::1b]:25: Cannot assign requested address
Dec 4 18:45:00 vpsxxxxxx postfix/smtp[3020]: 64DCD5EEC4: to=<user#gmail.com>, relay=gmail-smtp-in.l.google.com[66.102.1.27]:25, delay=1.7, delays=0.25/0.01/0.52/0.91, dsn=2.0.0, status=sent (250 2.0.0 OK 1543945500 f16si12703624wrt.428 - gsmtp)
Dec 4 18:45:00 vpsxxxxxx postfix/qmgr[2865]: 64DCD5EEC4: removed
Dec 4 18:45:01 vpsxxxxxx dovecot: imap-login: Login: user=<user#domain.com>, method=PLAIN, rip=xxx.xxx.xxx.xxx, lip=yyy.yyy.yyy.yyy, mpid=3025, TLS, session=<HDgM0zV8EcXE5dog>
Dec 4 18:45:01 vpsxxxxxx dovecot: imap-login: Login: user=<user#domain.com>, method=PLAIN, rip=xxx.xxx.xxx.xxx, lip=yyy.yyy.yyy.yyy, mpid=3026, TLS, session=<dIQM0zV8EsXE5dog>
Dec 4 18:45:01 vpsxxxxxx dovecot: imap(user#domain.com): Logged out in=1669 out=552
config.inc.php
<?php
$config['db_dsnw'] = 'mysql://databaseuser:password#localhost/database';
$config['default_host'] = 'localhost';
$config['smtp_server'] = 'mail.domain.com';
$config['support_url'] = '';
$config['ip_check'] = true;
$config['des_key'] = 'DES_KEY';
$config['username_domain'] = 'domain.com';
$config['product_name'] = 'domain Webmail';
$config['plugins'] = array(
'acl', 'additional_message_headers', 'archive', 'attachment_reminder', 'autologon',
'debug_logger', 'emoticons', 'enigma', 'example_addressbook', 'help', 'hide_blockquote',
'http_authentication', 'identicon', 'identity_select', 'jqueryui', 'krb_authentication',
'managesieve', 'markasjunk', 'new_user_dialog', 'new_user_identity', 'newmail_notifier',
'password', 'redundant_attachments', 'show_additional_headers', 'squirrelmail_usercopy',
'subscriptions_option', 'userinfo', 'vcard_attachments', 'virtuser_file', 'virtuser_query', 'zipdownload'
);
$config['language'] = 'en_EN';
$config['enable_spellcheck'] = false;
?>
domain.com is my Domain name
It was a configuration problem. I add this to config.inc.php, and it works
$config['smtp_server'] = 'tls://mail.domain.com';
$config['smtp_port'] = 587;
$config['smtp_user'] = '%u';
$config['smtp_pass'] = '%p';
$config['smtp_conn_options'] = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
),
);

Sorting a Meteor Cursor

I am using Ionic 2 with Meteor/Mongo.
I am trying to sort a Cursor, but find it just keeps the original order which the items were inserted.
model
interface Chat {
_id?: string;
memberIds?: string[];
title?: string;
subTitle?: string;
picture?: string;
lastMessage?: Message;
lastMessageCreatedAt?: Date;
receiverComp?: Tracker.Computation;
lastMessageComp?: Tracker.Computation;
}
ts
private sortLocalChats(): void {
this.localChatCursor = this.localChatCollection.find({}, { sort: { lastMessageCreatedAt: -1 } });
this.localChatCursor.forEach((chat: Chat) => {
console.log(chat.title+' '+chat.lastMessageCreatedAt);
});
console.log('==> loaded sorted local chats: ' + this.localChatCollection.find().count());
output
Ashton Marais Thu Oct 06 2016 16:50:36 GMT+0800 (CST)
Ashton Marais Wed Oct 12 2016 21:20:18 GMT+0800 (CST)
ghjghj ghjghg Wed Oct 05 2016 23:37:49 GMT+0800 (CST)
Brett Simpson Thu Oct 06 2016 23:52:05 GMT+0800 (CST)
==> loaded sorted local chats: 4
I would have expected this to be sorted by lastMessageCreatedAt.
Any help appreciated.
To get sorted results you probably need to call fetch() first. So in the above example this works:
this.localChatCursor.fetch().forEach(...);

Perl Fastcgi - HTTP::Message content must be bytes at

I am getting the following errors:
[Fri Feb 19 08:55:41 2016] [error] [client 172.16.30.100] FastCGI:
server "/home/admin/soap/server.fcgi" stderr: HTTP::Message content
must be bytes at
/usr/local/lib/perl5/site_perl/5.8.9/SOAP/Transport/HTTP.pm line 317
[Fri Feb 19 08:55:41 2016] [error] [client 172.16.30.100] FastCGI:
incomplete headers (0 bytes) received from server
"/home/admin/soap/server.fcgi" [Fri Feb 19 08:55:41 2016] [warn]
FastCGI: server "/home/admin/soap/server.fcgi" (pid 45466) terminated
by calling exit with status '255'
Here is line 317 of HTTP.pm I appreciate any input on a fix.
$self->response(HTTP::Response->new(
$code => undef,
HTTP::Headers->new(
'SOAPServer' => $self->product_tokens,
$compressed ? (
'Content-Encoding' => $COMPRESS) : (),
'Content-Type' => join(
'; ',
'text/xml',
!$SOAP::Constants::DO_NOT_USE_CHARSET && $encoding ? 'charset=' . lc($encoding) : ()
),
'Content-Length' => SOAP::Utils::bytelength $response),
$response,
));
$self->response->headers->header('Content-Type' => 'Multipart/Related; type="text/xml"; start="<main_envelope>"; boundary="'.$is_multipart.'"') if $is_multipart; }
Error message is pretty much telling you all about it: content for HTTP::Response object that you provide with $response variable must be bytes - i.e. a buffer without any characters outside 0-255 range. Use Encode::encode to transform it from Perl internal representation to whatever encoding required for your protocol.
By the way, this has nothing to do with fastcgi. The first error cause the script to die without emitting a response, resulting in the second error message.

Retrieve AEM Page Properties via Search/QueryBuilder API

Is there a way to retrieve data stored as page metadata (Page Properties) stored in a separate JCR node via the QueryBuilder API?
Example:
The search results should include the data under ~/article-1/jcr:content/thumbnail. However, the only results I am getting are data under the ~article-1/jcr:content/content (a parsys included on the template).
An example query:
http://localhost:4502/bin/querybuilder.json?p.hits=full&path=/content/path/to/articles
Results in (snippet):
{
"jcr:path":"/content/path/to/articles/article-1",
"jcr:createdBy":"admin",
"jcr:created":"Tue Dec 03 2013 16:26:51 GMT-0500",
"jcr:primaryType":"cq:Page"
},
{
"jcr:path":"/content/path/to/articles/article-1/jcr:content",
"sling:resourceType":"myapp/components/global/page/productdetail",
"jcr:lockIsDeep":true,
"jcr:uuid":"4ddebe08-82e1-44e9-9197-4241dca65bdf",
"jcr:title":"Article 1",
"jcr:mixinTypes":[
"mix:lockable",
"mix:versionable"
],
"jcr:created":"Tue Dec 03 2013 16:26:51 GMT-0500",
"jcr:baseVersion":"24cabbda-1e56-4d37-bfba-d0d52aba1c00",
"cq:lastReplicationAction":"Activate",
"jcr:isCheckedOut":true,
"cq:template":"/apps/myapp/templates/global/productdetail",
"cq:lastModifiedBy":"admin",
"jcr:primaryType":"cq:PageContent",
"jcr:predecessors":[
"24cabbda-1e56-4d37-bfba-d0d52aba1c00"
],
"cq:tags":[
"mysite:mytag"
],
"jcr:createdBy":"admin",
"jcr:versionHistory":"9dcd41d4-2e10-4d52-b0c0-1ea20e102e68",
"cq:lastReplicatedBy":"admin",
"cq:lastModified":"Mon Dec 09 2013 17:57:59 GMT-0500",
"cq:lastReplicated":"Mon Dec 16 2013 11:42:54 GMT-0500",
"jcr:lockOwner":"admin"
}
Search configuration is the out-of-the-box default.
EDIT: Data is returning in JSON, however, is not accessable in the API:
Result:
{
"success":true,
"results":2,
"total":2,
"offset":0,
"hits":[
{
"jcr:path":"/content/path/to/articles/article-a",
"jcr:createdBy":"admin",
"jcr:created":"Tue Dec 03 2013 16:27:01 GMT-0500",
"jcr:primaryType":"cq:Page",
"jcr:content":{
"sling:resourceType":"path/to/components/global/page/productdetail",
"_comment":"// ***SNIP*** //",
"thumbnail":{
"jcr:lastModifiedBy":"admin",
"imageRotate":"0",
"jcr:lastModified":"Wed Dec 04 2013 12:10:47 GMT-0500",
"jcr:primaryType":"nt:unstructured"
}
}
},
{
"jcr:path":"/content/path/to/articles/article-1",
"jcr:createdBy":"admin",
"jcr:created":"Tue Dec 03 2013 16:26:51 GMT-0500",
"jcr:primaryType":"cq:Page",
"jcr:content":{
"sling:resourceType":"path/to/components/global/page/productdetail",
"_comment":"// ***SNIP*** //",
"thumbnail":{
"jcr:lastModifiedBy":"admin",
"imageRotate":"0",
"fileReference":"/content/dam/path/to/IBMDemo/apparel/women/wsh005_shoes/WSH005_0533_is_main.jpg",
"jcr:lastModified":"Mon Dec 09 2013 17:57:58 GMT-0500",
"jcr:primaryType":"nt:unstructured"
}
}
}
]
}
Implementation code:
searchCriteria.put("path", path);
searchCriteria.put("type", "cq:Page");
searchCriteria.put("p.offset", offset.toString());
searchCriteria.put("p.limit", limit.toString());
searchCriteria.put("p.hits", "full");
searchCriteria.put("p.properties", "thumbnail");
searchCriteria.put("p.nodedepth", "2");
PredicateGroup predicateGroup = PredicateGroup.create(searchCriteria);
Query query = queryBuilder.createQuery(predicateGroup, session);
SearchResult result = query.getResult();
for (Hit hit : result.getHits()) {
try {
ValueMap properties = hit.getProperties();
VFSearchResult res = new VFSearchResult();
res.setUrl(hit.getPath());
res.setImageUrl((String)properties.get("thumbnail"));
res.setTags((String[])properties.get("cq:tags"));
res.setTeaserText((String)properties.get("teaserText"));
res.setTitle((String)properties.get("jcr:title"));
searchResults.add(res);
} catch (RepositoryException rex) {
logger.debug(String.format("could not retrieve node properties: %1s", rex));
}
}
After setting the path in the query, then set one or more property filters, such as in this example:
type=cq:Page
path=/content/path/to/articles
property=jcr:content/thumbnail
property.operation=exists
p.hits=selective
p.properties=jcr:content/thumbnail someSpecificThumbnailPropertyToRetrieve
p.limit=100000
You can set those on /libs/cq/search/content/querydebug.html and then also use that to get the JSON URL for the same query.
Check this out for some other examples: http://dev.day.com/docs/en/cq/5-5/dam/customizing_and_extendingcq5dam/query_builder.html
You could use CURL to retrieve node properties in the HTML/ JSON/ XML format. All you have to do is install download CURL and run your curl commands from your terminal from the same directory as the curl's .exe file.
HTML example:
C:\Users\****\Desktop>curl -u username:password http://localhost:4502/content/geometrixx-media/en/gadgets/leaps-in-ai.html
JSON example:
**C:\Users\****\Desktop>**curl -u username:password http://localhost:4502/content/geometrixx-media/en/gadgets/leaps-in-ai.html.tidy.infinity.json
Note: infinity in the above query ensures you get every property of every node under your specified path recursively

Rails I18n locale set date format in Rails

My environment: rails => 3.0.6, ruby => 1.9.2
I set my locale to Italan. Infact, inside the console
I18n.locale # => :it
My locale file work just fine, but I'cant make my dates display right. For ex. in my console
Date.current => Sun, 05 Jun 2011
instead of
05 Giugno 2011
But if I try other methods it return the right translated output
helper.number_to_currency(30) # => "30.00 €"
Locale issue occurs only with dates. Why?
Date.current => Sun, 05 Jun 2011
Won't run your code through the localizer, you should use
I18n.localize(Date.current)
I18n.l(Date.current)
There are also the helper methods in Rails, which will respect the locale, but are only (typically) available in the view, documentation for these lives here: http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html
Here's a short excerpt from an IRB session in a Rails 3.0.7 application (I don't have the other locales available)
ruby-1.9.2-p180 :001 > Date.current
=> Sun, 05 Jun 2011
ruby-1.9.2-p180 :002 > I18n.locale
=> :en
ruby-1.9.2-p180 :003 > I18n.l(Date.current)
=> "2011-06-05"
ruby-1.9.2-p180 :004 > I18n.locale = :ru
=> :ru
ruby-1.9.2-p180 :005 > I18n.l(Date.current)
=> I18n::MissingTranslationData: translation missing: ru.date.formats.default
Try
I18n.localize(Date.today)
or in the view just
l(Date.today)
Source:
http://guides.rubyonrails.org/i18n.html#adding-date-time-formats