Canadian prime minister Justin Trudeau will resign after leading the country for nine years.