Sliding Expiration in Redis using Redisson - redis

Redisson implementation is not working when deployed to AWS Environment
I have built a POC With Spring boot application to implement Sliding expiration of a cache in Redis using redisson client. It is working fine in my Local Env. but now my challenge is when I tried to apply the configuration to our existing code and deployed it to AWS Env. it is not giving the cached values.
Is there anything I forgot to specify? config? annotations?
I have used below configurations for Redisson
#Bean(name = "sessionCacheManager")
public CacheManager cacheManager(RedissonClient redissonClient) throws IOException
{
Map <String, CacheConfig> config = new HashMap <>();
CacheConfig configItem = new CacheConfig(0, Long.parseLong(maxIdleTime));
config.put("sso_client",configItem);
return new RedissonSpringCacheManager(redissonClient, config);
}
#Bean(destroyMethod = "shutdown")
public RedissonClient redissonClient() throws IOException {
Config config = new Config();
config.setNettyThreads(Integer.parseInt(nettyTrade)).setThreads(64).useReplicatedServers()
.setScanInterval(2000)
.addNodeAddress(address)
.setConnectTimeout(Integer.parseInt(connectTimeout))
.setTimeout(Integer.parseInt(timeout))
.setRetryAttempts(Integer.parseInt(retryAttempts))
.setRetryInterval(Integer.parseInt(retryInterval));
redisson = Redisson.create(config);
logger.debug("RedissonClient Bean has been created");
return redisson;
}
and this is how I get and update the cache
#Component
#CacheConfig(cacheNames = "sso_client", cacheManager = "sessionCacheManager")
public class SSOClientAuthenticationService
{
private static final Logger logger = Logger.getLogger(SSOClientAuthenticationService.class);
#Autowired
private CacheManager sessionCacheManager;
#Cacheable( key = "#clientAccessKey", unless = "#result == null")
public String getSSOSessionKey(String clientAccessKey)
{
logger.debug("Inside getSSOSessionKey()" + clientAccessKey);
org.springframework.cache.support.SimpleValueWrapper value = (org.springframework.cache.support.SimpleValueWrapper) sessionCacheManager.getCache("sso_client").get(clientAccessKey);
if(value!=null && (value.get() instanceof String))
{
logger.debug("session active" + value.get());
return (String)value.get();
}
logger.debug("session is out for ClientAccessKey" + clientAccessKey);
return null;
}
#CachePut(key = "#clientAccessKey", condition = "#result != null")
public String updateClientRequestMapping(String clientAccessKey, String sessionKey)
{
logger.debug("Inside updateClientRequestMapping()");
return sessionKey;
}
#CacheEvict(key = "#clientAccessKey", condition = "#result != null")
public String removeClientRequestMapping(String clientAccessKey)
{
logger.debug("Evict removeClientRequestMapping: " + clientAccessKey);
return clientAccessKey;
}
}
This is the log I got from splunk
2022-07-02 22:38:27 DEBUG o.r.c.ReplicatedConnectionManager - Current master myr1xfltu6ld0ybp.cxsbjl.ng.0001.use1.cache.amazonaws.com/10.4.14.237:6379 unchanged
2022-07-02 22:38:27 DEBUG org.redisson.command.RedisExecutor - acquired connection for command (GET) and params [[115, 101, 115, 115, 105, 111, 110, 83, 105, 109, ...]] from slot NodeSource [slot=0, addr=null, redisClient=null, redirect=null, entry=null] using node kyrld0ybp.cbjl.ng.0001.use1.cache.amazonaws.com/10.4.14.237:6379... RedisConnection#599724954 [redisClient=[addr=redis://kyrld0ybp.cbjl.ng.0001.use1.cache.amazonaws.com:6379], channel=[id: 0x0610f655, L:/10.4.11.206:35298 - R:kyrld0ybp.cbjl.ng.0001.use1.cache.amazonaws.com/10.4.14.237:6379], currentCommand=null, usage=1]
2022-07-02 22:38:27 DEBUG org.redisson.command.RedisExecutor - connection released for command (GET) and params [[115, 101, 115, 115, 105, 111, 110, 83, 105, 109, ...]] from slot NodeSource [slot=0, addr=null, redisClient=null, redirect=null, entry=null] using connection RedisConnection#599724954 [redisClient=[addr=redis://kyrld0ybp.cbjl.ng.0001.use1.cache.amazonaws.com:6379], channel=[id: 0x0610f655, L:/10.4.11.206:35298 - R:kyrld0ybp.cbjl.ng.0001.use1.cache.amazonaws.com/10.4.14.237:6379], currentCommand=CommandData [promise=java.util.concurrent.CompletableFuture#2121da78[Completed normally], command=(GET), params=[[115, 101, 115, 115, 105, 111, 110, 83, 105, 109, ...]], codec=org.redisson.client.codec.ByteArrayCodec], usage=0]
2022-07-02 22:38:27 DEBUG org.redisson.command.RedisExecutor - acquired connection for command (GET) and params [[115, 101, 115, 115, 105, 111, 110, 83, 105, 109, ...]] from slot NodeSource [slot=0, addr=null, redisClient=null, redirect=null, entry=null] using node kyrld0ybp.cbjl.ng.0001.use1.cache.amazonaws.com/10.4.14.237:6379... RedisConnection#632704404 [redisClient=[addr=redis://kyrld0ybp.cbjl.ng.0001.use1.cache.amazonaws.com:6379], channel=[id: 0x67d414b2, L:/10.4.11.206:35300 - R:kyrld0ybp.cbjl.ng.0001.use1.cache.amazonaws.com/10.4.14.237:6379], currentCommand=null, usage=1]
2022-07-02 22:38:27 DEBUG org.redisson.command.RedisExecutor - connection released for command (GET) and params [[115, 101, 115, 115, 105, 111, 110, 83, 105, 109, ...]] from slot NodeSource [slot=0, addr=null, redisClient=null, redirect=null, entry=null] using connection RedisConnection#632704404 [redisClient=[addr=redis://kyrld0ybp.cbjl.ng.0001.use1.cache.amazonaws.com:6379], channel=[id: 0x67d414b2, L:/10.4.11.206:35300 - R:kyrld0ybp.cbjl.ng.0001.use1.cache.amazonaws.com/10.4.14.237:6379], currentCommand=CommandData [promise=java.util.concurrent.CompletableFuture#6c2d2f7d[Completed normally], command=(GET), params=[[115, 101, 115, 115, 105, 111, 110, 83, 105, 109, ...]], codec=org.redisson.client.codec.ByteArrayCodec], usage=0]
thanks
zola

Related

aiogram.utils.exceptions.WrongFileIdentifier: Wrong file identifier/http url specified

I want to make a bot to which you send a link to the file, and it sends you the file, but I get an error from the header. I also tried to send InputFile object, but nothing was sent. Here's my code
from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor
from aiogram.types.input_file import InputFile
bot = Bot(token = '')
dp = Dispatcher(bot)
#dp.message_handler()
async def send_playlist(message: types.Message):
print(message.text)
await bot.send_document(message.chat.id, message.text)
executor.start_polling(dp)
Here's full error text
future: <Task finished name='Task-14' coro=<Dispatcher._process_polling_updates() done, defined at B:\portable_soft\python\lib\site-packages\aiogram\dispatcher\dispatcher.py:331> exception=WrongFileIdentifier('Wrong file identifier/http url specified')>
Traceback (most recent call last):
File "B:\portable_soft\python\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 339, in _process_polling_updates
for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
File "B:\portable_soft\python\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 194, in process_updates
return await asyncio.gather(*tasks)
File "B:\portable_soft\python\lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
File "B:\portable_soft\python\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 214, in process_update
return await self.message_handlers.notify(update.message)
File "B:\portable_soft\python\lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
File "B:\portable_soft\adb\file_bot.py", line 12, in send_playlist
await bot.send_document(message.chat.id, message.text)
File "B:\portable_soft\python\lib\site-packages\aiogram\bot\bot.py", line 402, in send_document
result = await self.request(api.Methods.SEND_DOCUMENT, payload, files)
File "B:\portable_soft\python\lib\site-packages\aiogram\bot\base.py", line 201, in request
return await api.make_request(self.session, self.__token, method, data, files,
File "B:\portable_soft\python\lib\site-packages\aiogram\bot\api.py", line 104, in make_request
return check_result(method, response.content_type, response.status, await response.text())
File "B:\portable_soft\python\lib\site-packages\aiogram\bot\api.py", line 78, in check_result
exceptions.BadRequest.detect(description)
File "B:\portable_soft\python\lib\site-packages\aiogram\utils\exceptions.py", line 136, in detect
raise err(cls.text or description)
aiogram.utils.exceptions.WrongFileIdentifier: Wrong file identifier/http url specified```
From your question, I don't really understand what you are trying to do. If you describe your use case a little better, I can probably suggest something more useful. What are you trying to do with playlists?
Here is one way to work with files:
#dp.message_handler(regexp='(^cat[s]?$|puss)')
async def cats(message: types.Message):
with open('data/cats.jpg', 'rb') as photo:
'''
# Old fashioned way:
await bot.send_photo(
message.chat.id,
photo,
caption='Cats are here 😺',
reply_to_message_id=message.message_id,
)
'''
await message.reply_photo(photo, caption='Cats are here 😺')
I actually prefer using FileIDs but I am not sure if that will help you.
Um, just write:
await bot.send_message(...)
but not:
await bot.send_DOCUMENT(...)
and if an error pops up:
from aiogram import md
await bot.send_message(msg.from_user.id, md.quote_html(msg.text))

softlayer User_Customer function changeUsername returns not supported

I am using the softLayer python API to change a username.
new_creds = {
'username': new_username,
'password': new_password
}
rc = client['User_Customer'].changeUsername(new_creds, id=user_id)
However I get the following exception:
...
File "/usr/local/lib/python2.7/dist-packages/SoftLayer/API.py", line 392, in call_handler
return self(name, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/SoftLayer/API.py", line 360, in call
return self.client.call(self.name, name, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/SoftLayer/API.py", line 263, in call
return self.transport(request)
File "/usr/local/lib/python2.7/dist-packages/SoftLayer/transports.py", line 195, in __call__
raise _ex(ex.faultCode, ex.faultString)
SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(Client): Function ("changeUsername") is not a valid method for this service
Is changeUsername not supported?
Currently the SoftLayer_User_Customer::changeUsername method is no longer supported. An issue is going to be reported in order to remove it from the SLDN documentation.

Oracle 12c to 11g

I designed a windows form application that connects to oracle 12c server.
Everything was great until I discovered that the client has a 32 bit operating system, and oracle c can only be installed on 64 bit operating systems.
I have been trying for a week to adapt my application to work with oracle 11g since this version can be installed in my client's computer, and it is becoming a hopeless task.
ODBC for oracle 11g does not have Oracle.ManagedDataAccess.dll included, and also Oracle.DataAccess cannot read Boolean datatypes from the stored procedures that I am using.
I either have to modify all my procedures, and try to fix all the issues related to Oracle.ManagedDataAccess.dll or start by developing a new application using oracle 11g.
I installed windows 7 32-bit on a virtual machine and had been working on it, started by a very small version of my application, and it I working, but requiring too much time !
Is there a faster way or solution to make my application compatible with oracle 11g ?
Is really oracle 11g more suitable for weak and limited computer than oracle 12c ? (In case I managed to convince the client to install a 64bit operating system and re-install all the programs he is using) : Client has 2GB of RAM
Update :
I installed the packed as instructed, and the application is now running. The only problem is that I am having an error when adding a parameter of type Boolean, the error is : 'Oracle.DataAccess.Client.OracleDbType' does not contain a definition for Boolean
this is the code I am using to call the procedure :
tring constr = "DATA SOURCE=localhost;PASSWORD=kidzclubadministration;PERSIST SECURITY INFO=True;USER ID=C##KidzClub";
OracleConnection con = new OracleConnection(constr);
OracleCommand cmd = new OracleCommand();
cmd.Connection = con;
con.Open();
cmd.CommandText = "get_admin_pass";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("pass", OracleDbType.NVarchar2);
cmd.Parameters["pass"].Direction = ParameterDirection.Input;
cmd.Parameters["pass"].Value = password;
cmd.Parameters.Add("done", OracleDbType.Boolean);
cmd.Parameters["done"].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
the exact error sentence is :
Error 2 'Oracle.DataAccess.Client.OracleDbType' does not contain a definition for 'Boolean' C:\Users\Jad-HP\Desktop\Windows Application\WindowsFormsApplication1\WindowsFormsApplication1\Form5.cs 44 53 WindowsFormsApplication1
I went to OracleDbType definition, and could not find a definition for Boolean :
#region Assembly Oracle.DataAccess.dll, v2.111.7.20
// C:\app\Jad-HP\product\11.1.0\client_2\ODP.NET\bin\2.x\Oracle.DataAccess.dll
#endregion
using System;
namespace Oracle.DataAccess.Client
{
public enum OracleDbType
{
BFile = 101,
Blob = 102,
Byte = 103,
Char = 104,
Clob = 105,
Date = 106,
Decimal = 107,
Double = 108,
Long = 109,
LongRaw = 110,
Int16 = 111,
Int32 = 112,
Int64 = 113,
IntervalDS = 114,
IntervalYM = 115,
NClob = 116,
NChar = 117,
NVarchar2 = 119,
Raw = 120,
RefCursor = 121,
Single = 122,
TimeStamp = 123,
TimeStampLTZ = 124,
TimeStampTZ = 125,
Varchar2 = 126,
XmlType = 127,
Array = 128,
Object = 129,
Ref = 130,
BinaryDouble = 132,
BinaryFloat = 133,
}
}
Although when going to that same definition in Visual studio where I am developing with oracle 12c, I have a definition for Boolean :
#region Assembly Oracle.DataAccess.dll, v4.121.1.0
// D:\app\Jad-HP\product\12.1.0\client_2\ODP.NET\bin\4\Oracle.DataAccess.dll
#endregion
using System;
namespace Oracle.DataAccess.Client
{
public enum OracleDbType
{
BFile = 101,
Blob = 102,
Byte = 103,
Char = 104,
Clob = 105,
Date = 106,
Decimal = 107,
Double = 108,
Long = 109,
LongRaw = 110,
Int16 = 111,
Int32 = 112,
Int64 = 113,
IntervalDS = 114,
IntervalYM = 115,
NClob = 116,
NChar = 117,
NVarchar2 = 119,
Raw = 120,
RefCursor = 121,
Single = 122,
TimeStamp = 123,
TimeStampLTZ = 124,
TimeStampTZ = 125,
Varchar2 = 126,
XmlType = 127,
Array = 128,
Object = 129,
Ref = 130,
BinaryDouble = 132,
BinaryFloat = 133,
Boolean = 134,
}
}
Is there a solution other then modifying all the procedures and replacing all Boolean variables ?
You can use the Oracle Managed Data Access DLL to talk to an 11g database. I have an application in production doing that right now.
I can't say I've yet installed an Oracle 12c database, nor even a 12c Oracle client, so I can't say whether either requires a 32-bit client. I got the Oracle Managed Data Access DLL from NuGet, and I avoid the need for an Oracle client by using a connect descriptor rather than a TNS name in the connection string. I don't see why you can't use this approach with your app.

Somehow the client detects the server's time zone in WCF

I have this scenario:
Server is in (GMT +3) time zone
Client is in (GMT -5) time zone
Server returns a DateTime to the client, let's say it is "10JAN2013 00:00" and AFAIK the DateTime has no time zone info attached to it. The time in the client side is converted into the client's time zone which is "09JAN2013 16:00"! the DTK is specified to DTK.Unspecified.
My question, how did the client know the time zone of the server if the DateTime has no timezone information? this is confusing to me! Is it sent in the header of SOAP or something like that?
They may or may not know. When DateTime objects are passed between client and server, they're serialized into some common format understood by the two parties. In some of those formats, such as XML, the time zone information is sent across the wire: if you have a DateTime with DateTimeKind.Utc, a 'Z' will be appended to the serialized date; for Local the timezone will be added, and for Unspecified nothing will be added, so the other party knows which format to use. In other formats, such as JSON, the server will not send anything in the date time if the kind is Utc, but will add the local time zone information for the other kinds (there's no distinction in the JSON format for Local and Unspecified; IIRC the receiving party will treat such information as Local).
If you want to see what goes on the wire, you can run the program below, while having a network capture tool such as Fiddler, to see what the client is sending to the server.
public class StackOverflow_14132566
{
[ServiceContract]
public interface ITest
{
[OperationContract]
[WebInvoke(RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedRequest)]
DateTime Add10Hours(DateTime input, string description);
}
public class Service : ITest
{
public DateTime Add10Hours(DateTime input, string description)
{
return input.AddHours(10);
}
}
public static void Test()
{
string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
host.AddServiceEndpoint(typeof(ITest), new BasicHttpBinding(), "basic");
host.AddServiceEndpoint(typeof(ITest), new WebHttpBinding(), "web").Behaviors.Add(new WebHttpBehavior());
host.Open();
Console.WriteLine("Host opened");
ChannelFactory<ITest> factory = new ChannelFactory<ITest>(new BasicHttpBinding(), new EndpointAddress(baseAddress + "/basic"));
ITest proxy = factory.CreateChannel();
Console.WriteLine(proxy.Add10Hours(new DateTime(2013, 1, 2, 19, 29, 0, DateTimeKind.Utc), "XML, UTC"));
Console.WriteLine(proxy.Add10Hours(new DateTime(2013, 1, 2, 19, 29, 0, DateTimeKind.Local), "XML, Local"));
Console.WriteLine(proxy.Add10Hours(new DateTime(2013, 1, 2, 19, 29, 0, DateTimeKind.Unspecified), "XML, Unspecified"));
((IClientChannel)proxy).Close();
factory.Close();
factory = new ChannelFactory<ITest>(new WebHttpBinding(), new EndpointAddress(baseAddress + "/web"));
factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
proxy = factory.CreateChannel();
Console.WriteLine(proxy.Add10Hours(new DateTime(2013, 1, 2, 19, 29, 0, DateTimeKind.Utc), "JSON, UTC"));
Console.WriteLine(proxy.Add10Hours(new DateTime(2013, 1, 2, 19, 29, 0, DateTimeKind.Local), "JSON, Local"));
Console.WriteLine(proxy.Add10Hours(new DateTime(2013, 1, 2, 19, 29, 0, DateTimeKind.Unspecified), "JSON, Unspecified"));
((IClientChannel)proxy).Close();
factory.Close();
Console.Write("Press ENTER to close the host");
Console.ReadLine();
host.Close();
}
}

How can I programmatically check if a server feature is installed in Windows Server 2008?

Specifically, I'm working with an application that only runs on Server 2008 if the "Desktop Experience" feature is installed, and I'd like to have that application's installer verify it's there.
The only way I'm aware of currently is to run ServerManagerCmd -query and parse the output; I'd prefer something more lightweight (like checking a registry key).
This is a code snippet of what I use to do it at runtime.
public static bool isServerFeatureInstalled(Win32_ServerFeature_ID id)
{
bool idFound = false;
ConnectionOptions connectionOptions = new ConnectionOptions();
ManagementScope managementScope =
new ManagementScope(
#"\\localhost\root\cimv2", connectionOptions);
ObjectQuery oQuery =
new ObjectQuery("SELECT Id FROM Win32_ServerFeature");
ManagementObjectSearcher oSearcher =
new ManagementObjectSearcher(managementScope, oQuery);
ManagementObjectCollection oReturnCollection = oSearcher.Get();
foreach (ManagementObject oReturn in oReturnCollection)
{
if ((uint) (oReturn["ID"]) == (uint) id)
{
return true;
}
}
return idFound;
}
// short list of names and values taken from MSDN.
public enum Win32_ServerFeature_ID
{
Application_Server = 1,
Web_Server = 2,
Media_Server = 3,
Windows_Sharepoint_Services = 4,
Fax_Server = 5,
File_Services = 6,
Print_Services = 7,
Active_Directory_Federation_Services = 8,
Active_Directory_Lightweight_Directory_Services = 9,
Active_Directory_Domain_Services = 10,
UDDI_Services = 11,
DHCP_Server = 12,
DNS_Server = 13,
Network_Policy_and_Access_Services = 14,
Certificate_Server = 16,
Active_Directory_Rights_Management_Services = 17,
Terminal_Services = 18,
Windows_Deployment_Services = 19,
Failover_Clustering = 33,
Network_Load_Balancing = 34,
Desktop_Experience = 35,
DOTNET_Framework_30 = 36,
}
On my testing Windows 2008 x64 std server running this command(adds the role):
ServerManagerCmd.exe -install AS-AppServer-Foundation
adds this registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppServer
This command (removes the role):
ServerManagerCmd.exe -remove AS-AppServer-Foundation
removes the key. So I'd think it's a good enough of an indicator.
These are just the results of my own research/experiment and is not an official/supported way of detecting if AppServer role is configured.